Browse code

integration-cli: DockerCLIInspectSuite: replace dockerCmd and waitRun

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2023/07/27 19:54:31
Showing 1 changed files
... ...
@@ -12,6 +12,7 @@ import (
12 12
 
13 13
 	"github.com/docker/docker/api/types"
14 14
 	"github.com/docker/docker/api/types/container"
15
+	"github.com/docker/docker/integration-cli/cli"
15 16
 	"gotest.tools/v3/assert"
16 17
 	"gotest.tools/v3/icmd"
17 18
 )
... ...
@@ -48,7 +49,7 @@ func (s *DockerCLIInspectSuite) TestInspectImage(c *testing.T) {
48 48
 }
49 49
 
50 50
 func (s *DockerCLIInspectSuite) TestInspectInt64(c *testing.T) {
51
-	dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true")
51
+	cli.DockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true")
52 52
 	inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory")
53 53
 	assert.Equal(c, inspectOut, "314572800")
54 54
 }
... ...
@@ -57,7 +58,7 @@ func (s *DockerCLIInspectSuite) TestInspectDefault(c *testing.T) {
57 57
 	// Both the container and image are named busybox. docker inspect will fetch the container JSON.
58 58
 	// If the container JSON is not available, it will go for the image JSON.
59 59
 
60
-	out, _ := dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
60
+	out := cli.DockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true").Stdout()
61 61
 	containerID := strings.TrimSpace(out)
62 62
 
63 63
 	inspectOut := inspectField(c, "busybox", "Id")
... ...
@@ -65,26 +66,25 @@ func (s *DockerCLIInspectSuite) TestInspectDefault(c *testing.T) {
65 65
 }
66 66
 
67 67
 func (s *DockerCLIInspectSuite) TestInspectStatus(c *testing.T) {
68
-	out := runSleepingContainer(c, "-d")
69
-	out = strings.TrimSpace(out)
68
+	id := runSleepingContainer(c, "-d")
70 69
 
71
-	inspectOut := inspectField(c, out, "State.Status")
70
+	inspectOut := inspectField(c, id, "State.Status")
72 71
 	assert.Equal(c, inspectOut, "running")
73 72
 
74 73
 	// Windows does not support pause/unpause on Windows Server Containers.
75 74
 	// (RS1 does for Hyper-V Containers, but production CI is not setup for that)
76 75
 	if testEnv.DaemonInfo.OSType != "windows" {
77
-		dockerCmd(c, "pause", out)
78
-		inspectOut = inspectField(c, out, "State.Status")
76
+		cli.DockerCmd(c, "pause", id)
77
+		inspectOut = inspectField(c, id, "State.Status")
79 78
 		assert.Equal(c, inspectOut, "paused")
80 79
 
81
-		dockerCmd(c, "unpause", out)
82
-		inspectOut = inspectField(c, out, "State.Status")
80
+		cli.DockerCmd(c, "unpause", id)
81
+		inspectOut = inspectField(c, id, "State.Status")
83 82
 		assert.Equal(c, inspectOut, "running")
84 83
 	}
85 84
 
86
-	dockerCmd(c, "stop", out)
87
-	inspectOut = inspectField(c, out, "State.Status")
85
+	cli.DockerCmd(c, "stop", id)
86
+	inspectOut = inspectField(c, id, "State.Status")
88 87
 	assert.Equal(c, inspectOut, "exited")
89 88
 }
90 89
 
... ...
@@ -94,7 +94,7 @@ func (s *DockerCLIInspectSuite) TestInspectTypeFlagContainer(c *testing.T) {
94 94
 	runSleepingContainer(c, "--name=busybox", "-d")
95 95
 
96 96
 	formatStr := "--format={{.State.Running}}"
97
-	out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
97
+	out := cli.DockerCmd(c, "inspect", "--type=container", formatStr, "busybox").Stdout()
98 98
 	assert.Equal(c, out, "true\n") // not a container JSON
99 99
 }
100 100
 
... ...
@@ -103,7 +103,7 @@ func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithNoContainer(c *testing.T)
103 103
 	// JSON. Since there is no container named busybox and --type=container, docker inspect will
104 104
 	// not try to get the image JSON. It will throw an error.
105 105
 
106
-	dockerCmd(c, "run", "-d", "busybox", "true")
106
+	cli.DockerCmd(c, "run", "-d", "busybox", "true")
107 107
 
108 108
 	_, _, err := dockerCmdWithError("inspect", "--type=container", "busybox")
109 109
 	// docker inspect should fail, as there is no container named busybox
... ...
@@ -115,9 +115,9 @@ func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithImage(c *testing.T) {
115 115
 	// JSON as --type=image. if there is no image with name busybox, docker inspect
116 116
 	// will throw an error.
117 117
 
118
-	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
118
+	cli.DockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
119 119
 
120
-	out, _ := dockerCmd(c, "inspect", "--type=image", "busybox")
120
+	out := cli.DockerCmd(c, "inspect", "--type=image", "busybox").Stdout()
121 121
 	// not an image JSON
122 122
 	assert.Assert(c, !strings.Contains(out, "State"))
123 123
 }
... ...
@@ -126,7 +126,7 @@ func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithInvalidValue(c *testing.T
126 126
 	// Both the container and image are named busybox. docker inspect will fail
127 127
 	// as --type=foobar is not a valid value for the flag.
128 128
 
129
-	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
129
+	cli.DockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
130 130
 
131 131
 	out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox")
132 132
 	assert.Assert(c, err != nil, "%d", exitCode)
... ...
@@ -144,7 +144,7 @@ func (s *DockerCLIInspectSuite) TestInspectImageFilterInt(c *testing.T) {
144 144
 
145 145
 	// now see if the size turns out to be the same
146 146
 	formatStr := fmt.Sprintf("--format={{eq .Size %d}}", size)
147
-	out, _ = dockerCmd(c, "inspect", formatStr, imageTest)
147
+	out = cli.DockerCmd(c, "inspect", formatStr, imageTest).Stdout()
148 148
 	result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
149 149
 	assert.NilError(c, err)
150 150
 	assert.Equal(c, result, true)
... ...
@@ -166,7 +166,7 @@ func (s *DockerCLIInspectSuite) TestInspectContainerFilterInt(c *testing.T) {
166 166
 
167 167
 	// now get the exit code to verify
168 168
 	formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode)
169
-	out, _ = dockerCmd(c, "inspect", formatStr, id)
169
+	out = cli.DockerCmd(c, "inspect", formatStr, id).Stdout()
170 170
 	inspectResult, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
171 171
 	assert.NilError(c, err)
172 172
 	assert.Equal(c, inspectResult, true)
... ...
@@ -181,7 +181,7 @@ func (s *DockerCLIInspectSuite) TestInspectBindMountPoint(c *testing.T) {
181 181
 		os.Mkdir(`c:\data`, os.ModeDir)
182 182
 	}
183 183
 
184
-	dockerCmd(c, "run", "-d", "--name", "test", "-v", prefix+slash+"data:"+prefix+slash+"data:ro"+modifier, "busybox", "cat")
184
+	cli.DockerCmd(c, "run", "-d", "--name", "test", "-v", prefix+slash+"data:"+prefix+slash+"data:ro"+modifier, "busybox", "cat")
185 185
 
186 186
 	vol := inspectFieldJSON(c, "test", "Mounts")
187 187
 
... ...
@@ -207,7 +207,7 @@ func (s *DockerCLIInspectSuite) TestInspectBindMountPoint(c *testing.T) {
207 207
 func (s *DockerCLIInspectSuite) TestInspectNamedMountPoint(c *testing.T) {
208 208
 	prefix, slash := getPrefixAndSlashFromDaemonPlatform()
209 209
 
210
-	dockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat")
210
+	cli.DockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat")
211 211
 
212 212
 	vol := inspectFieldJSON(c, "test", "Mounts")
213 213
 
... ...
@@ -229,7 +229,7 @@ func (s *DockerCLIInspectSuite) TestInspectNamedMountPoint(c *testing.T) {
229 229
 
230 230
 // #14947
231 231
 func (s *DockerCLIInspectSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) {
232
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
232
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
233 233
 	id := strings.TrimSpace(out)
234 234
 	startedAt := inspectField(c, id, "State.StartedAt")
235 235
 	finishedAt := inspectField(c, id, "State.FinishedAt")
... ...
@@ -250,7 +250,7 @@ func (s *DockerCLIInspectSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) {
250 250
 
251 251
 // #15633
252 252
 func (s *DockerCLIInspectSuite) TestInspectLogConfigNoType(c *testing.T) {
253
-	dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox")
253
+	cli.DockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox")
254 254
 	var logConfig container.LogConfig
255 255
 
256 256
 	out := inspectFieldJSON(c, "test", "HostConfig.LogConfig")
... ...
@@ -269,7 +269,7 @@ func (s *DockerCLIInspectSuite) TestInspectNoSizeFlagContainer(c *testing.T) {
269 269
 	runSleepingContainer(c, "--name=busybox", "-d")
270 270
 
271 271
 	formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}"
272
-	out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
272
+	out := cli.DockerCmd(c, "inspect", "--type=container", formatStr, "busybox").Stdout()
273 273
 	assert.Equal(c, strings.TrimSpace(out), "<nil>,<nil>", fmt.Sprintf("Expected not to display size info: %s", out))
274 274
 }
275 275
 
... ...
@@ -277,7 +277,7 @@ func (s *DockerCLIInspectSuite) TestInspectSizeFlagContainer(c *testing.T) {
277 277
 	runSleepingContainer(c, "--name=busybox", "-d")
278 278
 
279 279
 	formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
280
-	out, _ := dockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox")
280
+	out := cli.DockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox").Stdout()
281 281
 	sz := strings.Split(out, ",")
282 282
 
283 283
 	assert.Assert(c, strings.TrimSpace(sz[0]) != "<nil>")
... ...
@@ -335,8 +335,8 @@ func (s *DockerCLIInspectSuite) TestInspectStopWhenNotFound(c *testing.T) {
335 335
 }
336 336
 
337 337
 func (s *DockerCLIInspectSuite) TestInspectHistory(c *testing.T) {
338
-	dockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello")
339
-	dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg")
338
+	cli.DockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello")
339
+	cli.DockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg")
340 340
 	out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg")
341 341
 	assert.NilError(c, err)
342 342
 	assert.Assert(c, strings.Contains(out, "test comment"))
... ...
@@ -346,8 +346,8 @@ func (s *DockerCLIInspectSuite) TestInspectContainerNetworkDefault(c *testing.T)
346 346
 	testRequires(c, DaemonIsLinux)
347 347
 
348 348
 	contName := "test1"
349
-	dockerCmd(c, "run", "--name", contName, "-d", "busybox", "top")
350
-	netOut, _ := dockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge")
349
+	cli.DockerCmd(c, "run", "--name", contName, "-d", "busybox", "top")
350
+	netOut := cli.DockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge").Stdout()
351 351
 	out := inspectField(c, contName, "NetworkSettings.Networks")
352 352
 	assert.Assert(c, strings.Contains(out, "bridge"))
353 353
 	out = inspectField(c, contName, "NetworkSettings.Networks.bridge.NetworkID")
... ...
@@ -357,8 +357,8 @@ func (s *DockerCLIInspectSuite) TestInspectContainerNetworkDefault(c *testing.T)
357 357
 func (s *DockerCLIInspectSuite) TestInspectContainerNetworkCustom(c *testing.T) {
358 358
 	testRequires(c, DaemonIsLinux)
359 359
 
360
-	netOut, _ := dockerCmd(c, "network", "create", "net1")
361
-	dockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top")
360
+	netOut := cli.DockerCmd(c, "network", "create", "net1").Stdout()
361
+	cli.DockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top")
362 362
 	out := inspectField(c, "container1", "NetworkSettings.Networks")
363 363
 	assert.Assert(c, strings.Contains(out, "net1"))
364 364
 	out = inspectField(c, "container1", "NetworkSettings.Networks.net1.NetworkID")
... ...
@@ -379,9 +379,9 @@ func (s *DockerCLIInspectSuite) TestInspectAmpersand(c *testing.T) {
379 379
 	testRequires(c, DaemonIsLinux)
380 380
 
381 381
 	name := "test"
382
-	out, _ := dockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env")
382
+	out := cli.DockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env").Stdout()
383 383
 	assert.Assert(c, strings.Contains(out, `soanni&rtr`))
384
-	out, _ = dockerCmd(c, "inspect", name)
384
+	out = cli.DockerCmd(c, "inspect", name).Stdout()
385 385
 	assert.Assert(c, strings.Contains(out, `soanni&rtr`))
386 386
 }
387 387