diff --git a/integration/internal/container/ops.go b/integration/internal/container/ops.go index 21e9094065fb4..700014abb22cb 100644 --- a/integration/internal/container/ops.go +++ b/integration/internal/container/ops.go @@ -4,6 +4,7 @@ import ( "fmt" containertypes "github.com/docker/docker/api/types/container" + mounttypes "github.com/docker/docker/api/types/mount" networktypes "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/strslice" "github.com/docker/go-connections/nat" @@ -68,6 +69,13 @@ func WithWorkingDir(dir string) func(*TestContainerConfig) { } } +// WithMount adds an mount +func WithMount(m mounttypes.Mount) func(*TestContainerConfig) { + return func(c *TestContainerConfig) { + c.HostConfig.Mounts = append(c.HostConfig.Mounts, m) + } +} + // WithVolume sets the volume of the container func WithVolume(name string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { diff --git a/integration/internal/container/states.go b/integration/internal/container/states.go index 088407deb84eb..2397159188268 100644 --- a/integration/internal/container/states.go +++ b/integration/internal/container/states.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/docker/docker/client" + "github.com/pkg/errors" "gotest.tools/poll" ) @@ -39,3 +40,20 @@ func IsInState(ctx context.Context, client client.APIClient, containerID string, return poll.Continue("waiting for container to be one of (%s), currently %s", strings.Join(state, ", "), inspect.State.Status) } } + +// IsSuccessful verifies state.Status == "exited" && state.ExitCode == 0 +func IsSuccessful(ctx context.Context, client client.APIClient, containerID string) func(log poll.LogT) poll.Result { + return func(log poll.LogT) poll.Result { + inspect, err := client.ContainerInspect(ctx, containerID) + if err != nil { + return poll.Error(err) + } + if inspect.State.Status == "exited" { + if inspect.State.ExitCode == 0 { + return poll.Success() + } + return poll.Error(errors.Errorf("expected exit code 0, got %d", inspect.State.ExitCode)) + } + return poll.Continue("waiting for container to be \"exited\", currently %s", inspect.State.Status) + } +}