diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index 7b2aebfbbe..04f5aa31b0 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/integration-cli/docker_cli_inspect_test.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" + "github.com/docker/docker/integration-cli/cli" "gotest.tools/v3/assert" "gotest.tools/v3/icmd" ) @@ -48,7 +49,7 @@ func (s *DockerCLIInspectSuite) TestInspectImage(c *testing.T) { } func (s *DockerCLIInspectSuite) TestInspectInt64(c *testing.T) { - dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true") + cli.DockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true") inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory") assert.Equal(c, inspectOut, "314572800") } @@ -57,7 +58,7 @@ func (s *DockerCLIInspectSuite) TestInspectDefault(c *testing.T) { // Both the container and image are named busybox. docker inspect will fetch the container JSON. // If the container JSON is not available, it will go for the image JSON. - out, _ := dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") + out := cli.DockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true").Stdout() containerID := strings.TrimSpace(out) inspectOut := inspectField(c, "busybox", "Id") @@ -65,26 +66,25 @@ func (s *DockerCLIInspectSuite) TestInspectDefault(c *testing.T) { } func (s *DockerCLIInspectSuite) TestInspectStatus(c *testing.T) { - out := runSleepingContainer(c, "-d") - out = strings.TrimSpace(out) + id := runSleepingContainer(c, "-d") - inspectOut := inspectField(c, out, "State.Status") + inspectOut := inspectField(c, id, "State.Status") assert.Equal(c, inspectOut, "running") // Windows does not support pause/unpause on Windows Server Containers. // (RS1 does for Hyper-V Containers, but production CI is not setup for that) if testEnv.DaemonInfo.OSType != "windows" { - dockerCmd(c, "pause", out) - inspectOut = inspectField(c, out, "State.Status") + cli.DockerCmd(c, "pause", id) + inspectOut = inspectField(c, id, "State.Status") assert.Equal(c, inspectOut, "paused") - dockerCmd(c, "unpause", out) - inspectOut = inspectField(c, out, "State.Status") + cli.DockerCmd(c, "unpause", id) + inspectOut = inspectField(c, id, "State.Status") assert.Equal(c, inspectOut, "running") } - dockerCmd(c, "stop", out) - inspectOut = inspectField(c, out, "State.Status") + cli.DockerCmd(c, "stop", id) + inspectOut = inspectField(c, id, "State.Status") assert.Equal(c, inspectOut, "exited") } @@ -94,7 +94,7 @@ func (s *DockerCLIInspectSuite) TestInspectTypeFlagContainer(c *testing.T) { runSleepingContainer(c, "--name=busybox", "-d") formatStr := "--format={{.State.Running}}" - out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox") + out := cli.DockerCmd(c, "inspect", "--type=container", formatStr, "busybox").Stdout() assert.Equal(c, out, "true\n") // not a container JSON } @@ -103,7 +103,7 @@ func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithNoContainer(c *testing.T) // JSON. Since there is no container named busybox and --type=container, docker inspect will // not try to get the image JSON. It will throw an error. - dockerCmd(c, "run", "-d", "busybox", "true") + cli.DockerCmd(c, "run", "-d", "busybox", "true") _, _, err := dockerCmdWithError("inspect", "--type=container", "busybox") // docker inspect should fail, as there is no container named busybox @@ -115,9 +115,9 @@ func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithImage(c *testing.T) { // JSON as --type=image. if there is no image with name busybox, docker inspect // will throw an error. - dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") + cli.DockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") - out, _ := dockerCmd(c, "inspect", "--type=image", "busybox") + out := cli.DockerCmd(c, "inspect", "--type=image", "busybox").Stdout() // not an image JSON assert.Assert(c, !strings.Contains(out, "State")) } @@ -126,7 +126,7 @@ func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithInvalidValue(c *testing.T // Both the container and image are named busybox. docker inspect will fail // as --type=foobar is not a valid value for the flag. - dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") + cli.DockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox") assert.Assert(c, err != nil, "%d", exitCode) @@ -144,7 +144,7 @@ func (s *DockerCLIInspectSuite) TestInspectImageFilterInt(c *testing.T) { // now see if the size turns out to be the same formatStr := fmt.Sprintf("--format={{eq .Size %d}}", size) - out, _ = dockerCmd(c, "inspect", formatStr, imageTest) + out = cli.DockerCmd(c, "inspect", formatStr, imageTest).Stdout() result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")) assert.NilError(c, err) assert.Equal(c, result, true) @@ -166,7 +166,7 @@ func (s *DockerCLIInspectSuite) TestInspectContainerFilterInt(c *testing.T) { // now get the exit code to verify formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode) - out, _ = dockerCmd(c, "inspect", formatStr, id) + out = cli.DockerCmd(c, "inspect", formatStr, id).Stdout() inspectResult, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")) assert.NilError(c, err) assert.Equal(c, inspectResult, true) @@ -181,7 +181,7 @@ func (s *DockerCLIInspectSuite) TestInspectBindMountPoint(c *testing.T) { os.Mkdir(`c:\data`, os.ModeDir) } - dockerCmd(c, "run", "-d", "--name", "test", "-v", prefix+slash+"data:"+prefix+slash+"data:ro"+modifier, "busybox", "cat") + cli.DockerCmd(c, "run", "-d", "--name", "test", "-v", prefix+slash+"data:"+prefix+slash+"data:ro"+modifier, "busybox", "cat") vol := inspectFieldJSON(c, "test", "Mounts") @@ -207,7 +207,7 @@ func (s *DockerCLIInspectSuite) TestInspectBindMountPoint(c *testing.T) { func (s *DockerCLIInspectSuite) TestInspectNamedMountPoint(c *testing.T) { prefix, slash := getPrefixAndSlashFromDaemonPlatform() - dockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat") + cli.DockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat") vol := inspectFieldJSON(c, "test", "Mounts") @@ -229,7 +229,7 @@ func (s *DockerCLIInspectSuite) TestInspectNamedMountPoint(c *testing.T) { // #14947 func (s *DockerCLIInspectSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") + out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout() id := strings.TrimSpace(out) startedAt := inspectField(c, id, "State.StartedAt") finishedAt := inspectField(c, id, "State.FinishedAt") @@ -250,7 +250,7 @@ func (s *DockerCLIInspectSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) { // #15633 func (s *DockerCLIInspectSuite) TestInspectLogConfigNoType(c *testing.T) { - dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox") + cli.DockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox") var logConfig container.LogConfig out := inspectFieldJSON(c, "test", "HostConfig.LogConfig") @@ -269,7 +269,7 @@ func (s *DockerCLIInspectSuite) TestInspectNoSizeFlagContainer(c *testing.T) { runSleepingContainer(c, "--name=busybox", "-d") formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}" - out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox") + out := cli.DockerCmd(c, "inspect", "--type=container", formatStr, "busybox").Stdout() assert.Equal(c, strings.TrimSpace(out), ",", fmt.Sprintf("Expected not to display size info: %s", out)) } @@ -277,7 +277,7 @@ func (s *DockerCLIInspectSuite) TestInspectSizeFlagContainer(c *testing.T) { runSleepingContainer(c, "--name=busybox", "-d") formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'" - out, _ := dockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox") + out := cli.DockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox").Stdout() sz := strings.Split(out, ",") assert.Assert(c, strings.TrimSpace(sz[0]) != "") @@ -335,8 +335,8 @@ func (s *DockerCLIInspectSuite) TestInspectStopWhenNotFound(c *testing.T) { } func (s *DockerCLIInspectSuite) TestInspectHistory(c *testing.T) { - dockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello") - dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg") + cli.DockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello") + cli.DockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg") out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg") assert.NilError(c, err) assert.Assert(c, strings.Contains(out, "test comment")) @@ -346,8 +346,8 @@ func (s *DockerCLIInspectSuite) TestInspectContainerNetworkDefault(c *testing.T) testRequires(c, DaemonIsLinux) contName := "test1" - dockerCmd(c, "run", "--name", contName, "-d", "busybox", "top") - netOut, _ := dockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge") + cli.DockerCmd(c, "run", "--name", contName, "-d", "busybox", "top") + netOut := cli.DockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge").Stdout() out := inspectField(c, contName, "NetworkSettings.Networks") assert.Assert(c, strings.Contains(out, "bridge")) out = inspectField(c, contName, "NetworkSettings.Networks.bridge.NetworkID") @@ -357,8 +357,8 @@ func (s *DockerCLIInspectSuite) TestInspectContainerNetworkDefault(c *testing.T) func (s *DockerCLIInspectSuite) TestInspectContainerNetworkCustom(c *testing.T) { testRequires(c, DaemonIsLinux) - netOut, _ := dockerCmd(c, "network", "create", "net1") - dockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top") + netOut := cli.DockerCmd(c, "network", "create", "net1").Stdout() + cli.DockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top") out := inspectField(c, "container1", "NetworkSettings.Networks") assert.Assert(c, strings.Contains(out, "net1")) out = inspectField(c, "container1", "NetworkSettings.Networks.net1.NetworkID") @@ -379,9 +379,9 @@ func (s *DockerCLIInspectSuite) TestInspectAmpersand(c *testing.T) { testRequires(c, DaemonIsLinux) name := "test" - out, _ := dockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env") + out := cli.DockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env").Stdout() assert.Assert(c, strings.Contains(out, `soanni&rtr`)) - out, _ = dockerCmd(c, "inspect", name) + out = cli.DockerCmd(c, "inspect", name).Stdout() assert.Assert(c, strings.Contains(out, `soanni&rtr`)) }