mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: merge ContainerInspectWithRaw with ContainerInspect
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -127,10 +127,10 @@ func RunAttach(ctx context.Context, t *testing.T, apiClient client.APIClient, op
|
||||
|
||||
// Inspect to get the exit code. A new context is used here to make sure that if the context passed as argument as
|
||||
// reached timeout during the demultiplexStream call, we still return a RunResult.
|
||||
resp, err := apiClient.ContainerInspect(context.Background(), id)
|
||||
inspect, err := apiClient.ContainerInspect(context.Background(), id, client.ContainerInspectOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
return RunResult{ContainerID: id, ExitCode: resp.State.ExitCode, Stdout: &s.stdout, Stderr: &s.stderr}
|
||||
return RunResult{ContainerID: id, ExitCode: inspect.Container.State.ExitCode, Stdout: &s.stdout, Stderr: &s.stderr}
|
||||
}
|
||||
|
||||
type streams struct {
|
||||
@@ -187,10 +187,10 @@ func RemoveAll(ctx context.Context, t *testing.T, apiClient client.APIClient) {
|
||||
func Inspect(ctx context.Context, t *testing.T, apiClient client.APIClient, containerRef string) container.InspectResponse {
|
||||
t.Helper()
|
||||
|
||||
c, err := apiClient.ContainerInspect(ctx, containerRef)
|
||||
inspect, err := apiClient.ContainerInspect(ctx, containerRef, client.ContainerInspectOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
return c
|
||||
return inspect.Container
|
||||
}
|
||||
|
||||
type ContainerOutput struct {
|
||||
|
||||
@@ -14,12 +14,12 @@ import (
|
||||
// RunningStateFlagIs polls for the container's Running state flag to be equal to running.
|
||||
func RunningStateFlagIs(ctx context.Context, apiClient client.APIClient, containerID string, running bool) func(log poll.LogT) poll.Result {
|
||||
return func(log poll.LogT) poll.Result {
|
||||
inspect, err := apiClient.ContainerInspect(ctx, containerID)
|
||||
inspect, err := apiClient.ContainerInspect(ctx, containerID, client.ContainerInspectOptions{})
|
||||
|
||||
switch {
|
||||
case err != nil:
|
||||
return poll.Error(err)
|
||||
case inspect.State.Running == running:
|
||||
case inspect.Container.State.Running == running:
|
||||
return poll.Success()
|
||||
default:
|
||||
return poll.Continue("waiting for container to be %s", map[bool]string{true: "running", false: "stopped"}[running])
|
||||
@@ -35,19 +35,19 @@ func IsStopped(ctx context.Context, apiClient client.APIClient, containerID stri
|
||||
// IsInState verifies the container is in one of the specified state, e.g., "running", "exited", etc.
|
||||
func IsInState(ctx context.Context, apiClient client.APIClient, containerID string, state ...container.ContainerState) func(log poll.LogT) poll.Result {
|
||||
return func(log poll.LogT) poll.Result {
|
||||
inspect, err := apiClient.ContainerInspect(ctx, containerID)
|
||||
inspect, err := apiClient.ContainerInspect(ctx, containerID, client.ContainerInspectOptions{})
|
||||
if err != nil {
|
||||
return poll.Error(err)
|
||||
}
|
||||
for _, v := range state {
|
||||
if inspect.State.Status == v {
|
||||
if inspect.Container.State.Status == v {
|
||||
return poll.Success()
|
||||
}
|
||||
}
|
||||
if len(state) == 1 {
|
||||
return poll.Continue("waiting for container State.Status to be '%s', currently '%s'", state[0], inspect.State.Status)
|
||||
return poll.Continue("waiting for container State.Status to be '%s', currently '%s'", state[0], inspect.Container.State.Status)
|
||||
} else {
|
||||
return poll.Continue("waiting for container State.Status to be one of (%s), currently '%s'", strings.Join(state, ", "), inspect.State.Status)
|
||||
return poll.Continue("waiting for container State.Status to be one of (%s), currently '%s'", strings.Join(state, ", "), inspect.Container.State.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,30 +55,30 @@ func IsInState(ctx context.Context, apiClient client.APIClient, containerID stri
|
||||
// IsSuccessful verifies state.Status == "exited" && state.ExitCode == 0
|
||||
func IsSuccessful(ctx context.Context, apiClient client.APIClient, containerID string) func(log poll.LogT) poll.Result {
|
||||
return func(log poll.LogT) poll.Result {
|
||||
inspect, err := apiClient.ContainerInspect(ctx, containerID)
|
||||
inspect, err := apiClient.ContainerInspect(ctx, containerID, client.ContainerInspectOptions{})
|
||||
if err != nil {
|
||||
return poll.Error(err)
|
||||
}
|
||||
if inspect.State.Status == container.StateExited {
|
||||
if inspect.State.ExitCode == 0 {
|
||||
if inspect.Container.State.Status == container.StateExited {
|
||||
if inspect.Container.State.ExitCode == 0 {
|
||||
return poll.Success()
|
||||
}
|
||||
return poll.Error(errors.Errorf("expected exit code 0, got %d", inspect.State.ExitCode))
|
||||
return poll.Error(errors.Errorf("expected exit code 0, got %d", inspect.Container.State.ExitCode))
|
||||
}
|
||||
return poll.Continue("waiting for container to be %q, currently %s", container.StateExited, inspect.State.Status)
|
||||
return poll.Continue("waiting for container to be %q, currently %s", container.StateExited, inspect.Container.State.Status)
|
||||
}
|
||||
}
|
||||
|
||||
// IsRemoved verifies the container has been removed
|
||||
func IsRemoved(ctx context.Context, apiClient client.APIClient, containerID string) func(log poll.LogT) poll.Result {
|
||||
return func(log poll.LogT) poll.Result {
|
||||
inspect, err := apiClient.ContainerInspect(ctx, containerID)
|
||||
inspect, err := apiClient.ContainerInspect(ctx, containerID, client.ContainerInspectOptions{})
|
||||
if err != nil {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return poll.Success()
|
||||
}
|
||||
return poll.Error(err)
|
||||
}
|
||||
return poll.Continue("waiting for container to be removed, currently %s", inspect.State.Status)
|
||||
return poll.Continue("waiting for container to be removed, currently %s", inspect.Container.State.Status)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user