Skip to content

Exec Wait Strategy

The exec wait strategy will check the exit code of a process to be executed in the container, and allows to set the following conditions:

  • the command and arguments to be executed, as an array of strings.
  • a function to match a specific exit code, with the default matching 0.
  • the output response matcher as a function.
  • the startup timeout to be used in seconds, default is 60 seconds.
  • the poll interval to be used in milliseconds, default is 100 milliseconds.

Match an exit code and a response matcher

dockerReq := testcontainers.ContainerRequest{
    Image: "docker.io/nginx:latest",
    WaitingFor: wait.ForExec([]string{"echo", "hello world!"}).
        WithStartupTimeout(time.Second * 10).
        WithExitCodeMatcher(func(exitCode int) bool {
            return exitCode == 0
        }).
        WithResponseMatcher(func(body io.Reader) bool {
            data, _ := io.ReadAll(body)
            return bytes.Equal(data, []byte("hello world!\n"))
        }),
}