Browse code

integration-cli: DockerAPISuite: replace dockerCmd and waitRun

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

Sebastiaan van Stijn authored on 2023/07/27 20:13:00
Showing 10 changed files
... ...
@@ -13,6 +13,7 @@ import (
13 13
 	"github.com/docker/docker/api/types"
14 14
 	"github.com/docker/docker/api/types/container"
15 15
 	"github.com/docker/docker/client"
16
+	"github.com/docker/docker/integration-cli/cli"
16 17
 	"github.com/docker/docker/pkg/stdcopy"
17 18
 	"github.com/docker/docker/testutil"
18 19
 	"github.com/docker/docker/testutil/request"
... ...
@@ -24,14 +25,14 @@ import (
24 24
 )
25 25
 
26 26
 func (s *DockerAPISuite) TestGetContainersAttachWebsocket(c *testing.T) {
27
-	out, _ := dockerCmd(c, "run", "-di", "busybox", "cat")
27
+	cid := cli.DockerCmd(c, "run", "-di", "busybox", "cat").Stdout()
28
+	cid = strings.TrimSpace(cid)
28 29
 
29 30
 	rwc, err := request.SockConn(10*time.Second, request.DaemonHost())
30 31
 	assert.NilError(c, err)
31 32
 
32
-	cleanedContainerID := strings.TrimSpace(out)
33 33
 	config, err := websocket.NewConfig(
34
-		"/containers/"+cleanedContainerID+"/attach/ws?stream=1&stdin=1&stdout=1&stderr=1",
34
+		"/containers/"+cid+"/attach/ws?stream=1&stdin=1&stdout=1&stderr=1",
35 35
 		"http://localhost",
36 36
 	)
37 37
 	assert.NilError(c, err)
... ...
@@ -136,7 +137,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
136 136
 	}
137 137
 
138 138
 	// Create a container that only emits stdout.
139
-	cid, _ := dockerCmd(c, "run", "-di", "busybox", "cat")
139
+	cid := cli.DockerCmd(c, "run", "-di", "busybox", "cat").Stdout()
140 140
 	cid = strings.TrimSpace(cid)
141 141
 
142 142
 	// Attach to the container's stdout stream.
... ...
@@ -152,7 +153,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
152 152
 	expectTimeout(wc, br, "stdout")
153 153
 
154 154
 	// Test the similar functions of the stderr stream.
155
-	cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "cat >&2")
155
+	cid = cli.DockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "cat >&2").Stdout()
156 156
 	cid = strings.TrimSpace(cid)
157 157
 	wc, br, err = requestHijack(http.MethodPost, "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain", request.DaemonHost())
158 158
 	assert.NilError(c, err)
... ...
@@ -162,7 +163,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
162 162
 	expectTimeout(wc, br, "stderr")
163 163
 
164 164
 	// Test with tty.
165
-	cid, _ = dockerCmd(c, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2")
165
+	cid = cli.DockerCmd(c, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2").Stdout()
166 166
 	cid = strings.TrimSpace(cid)
167 167
 	// Attach to stdout only.
168 168
 	wc, br, err = requestHijack(http.MethodPost, "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain", request.DaemonHost())
... ...
@@ -181,7 +182,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
181 181
 	assert.NilError(c, err)
182 182
 	defer apiClient.Close()
183 183
 
184
-	cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "echo hello; cat")
184
+	cid = cli.DockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "echo hello; cat").Stdout()
185 185
 	cid = strings.TrimSpace(cid)
186 186
 
187 187
 	// Make sure we don't see "hello" if Logs is false
... ...
@@ -38,18 +38,17 @@ import (
38 38
 
39 39
 func (s *DockerAPISuite) TestContainerAPIGetAll(c *testing.T) {
40 40
 	startCount := getContainerCount(c)
41
-	name := "getall"
42
-	dockerCmd(c, "run", "--name", name, "busybox", "true")
41
+	const name = "getall"
42
+	cli.DockerCmd(c, "run", "--name", name, "busybox", "true")
43 43
 
44 44
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
45 45
 	assert.NilError(c, err)
46 46
 	defer apiClient.Close()
47 47
 
48
-	options := container.ListOptions{
49
-		All: true,
50
-	}
51 48
 	ctx := testutil.GetContext(c)
52
-	containers, err := apiClient.ContainerList(ctx, options)
49
+	containers, err := apiClient.ContainerList(ctx, container.ListOptions{
50
+		All: true,
51
+	})
53 52
 	assert.NilError(c, err)
54 53
 	assert.Equal(c, len(containers), startCount+1)
55 54
 	actual := containers[0].Names[0]
... ...
@@ -59,7 +58,7 @@ func (s *DockerAPISuite) TestContainerAPIGetAll(c *testing.T) {
59 59
 // regression test for empty json field being omitted #13691
60 60
 func (s *DockerAPISuite) TestContainerAPIGetJSONNoFieldsOmitted(c *testing.T) {
61 61
 	startCount := getContainerCount(c)
62
-	dockerCmd(c, "run", "busybox", "true")
62
+	cli.DockerCmd(c, "run", "busybox", "true")
63 63
 
64 64
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
65 65
 	assert.NilError(c, err)
... ...
@@ -101,8 +100,8 @@ func (s *DockerAPISuite) TestContainerAPIGetJSONNoFieldsOmitted(c *testing.T) {
101 101
 func (s *DockerAPISuite) TestContainerAPIGetExport(c *testing.T) {
102 102
 	// Not supported on Windows as Windows does not support docker export
103 103
 	testRequires(c, DaemonIsLinux)
104
-	name := "exportcontainer"
105
-	dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test")
104
+	const name = "exportcontainer"
105
+	cli.DockerCmd(c, "run", "--name", name, "busybox", "touch", "/test")
106 106
 
107 107
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
108 108
 	assert.NilError(c, err)
... ...
@@ -128,8 +127,8 @@ func (s *DockerAPISuite) TestContainerAPIGetExport(c *testing.T) {
128 128
 func (s *DockerAPISuite) TestContainerAPIGetChanges(c *testing.T) {
129 129
 	// Not supported on Windows as Windows does not support docker diff (/containers/name/changes)
130 130
 	testRequires(c, DaemonIsLinux)
131
-	name := "changescontainer"
132
-	dockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd")
131
+	const name = "changescontainer"
132
+	cli.DockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd")
133 133
 
134 134
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
135 135
 	assert.NilError(c, err)
... ...
@@ -170,7 +169,7 @@ func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) {
170 170
 
171 171
 	// allow some time to stream the stats from the container
172 172
 	time.Sleep(4 * time.Second)
173
-	dockerCmd(c, "rm", "-f", name)
173
+	cli.DockerCmd(c, "rm", "-f", name)
174 174
 
175 175
 	// collect the results from the stats stream or timeout and fail
176 176
 	// if the stream was not disconnected.
... ...
@@ -187,8 +186,7 @@ func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) {
187 187
 }
188 188
 
189 189
 func (s *DockerAPISuite) TestGetContainerStatsRmRunning(c *testing.T) {
190
-	out := runSleepingContainer(c)
191
-	id := strings.TrimSpace(out)
190
+	id := runSleepingContainer(c)
192 191
 
193 192
 	buf := &ChannelBuffer{C: make(chan []byte, 1)}
194 193
 	defer buf.Close()
... ...
@@ -218,7 +216,7 @@ func (s *DockerAPISuite) TestGetContainerStatsRmRunning(c *testing.T) {
218 218
 	_, err = buf.ReadTimeout(b, 2*time.Second)
219 219
 	assert.NilError(c, err)
220 220
 
221
-	dockerCmd(c, "rm", "-f", id)
221
+	cli.DockerCmd(c, "rm", "-f", id)
222 222
 	assert.Assert(c, <-chErr == nil)
223 223
 }
224 224
 
... ...
@@ -254,7 +252,7 @@ func (c *ChannelBuffer) ReadTimeout(p []byte, n time.Duration) (int, error) {
254 254
 // previous test was just checking one stat entry so it didn't fail (stats with
255 255
 // stream false always return one stat)
256 256
 func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) {
257
-	name := "statscontainer"
257
+	const name = "statscontainer"
258 258
 	runSleepingContainer(c, "--name", name)
259 259
 
260 260
 	type b struct {
... ...
@@ -275,7 +273,7 @@ func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) {
275 275
 
276 276
 	// allow some time to stream the stats from the container
277 277
 	time.Sleep(4 * time.Second)
278
-	dockerCmd(c, "rm", "-f", name)
278
+	cli.DockerCmd(c, "rm", "-f", name)
279 279
 
280 280
 	// collect the results from the stats stream or timeout and fail
281 281
 	// if the stream was not disconnected.
... ...
@@ -295,7 +293,7 @@ func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) {
295 295
 }
296 296
 
297 297
 func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) {
298
-	name := "statscontainer"
298
+	const name = "statscontainer2"
299 299
 	runSleepingContainer(c, "--name", name)
300 300
 
301 301
 	type b struct {
... ...
@@ -317,7 +315,7 @@ func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) {
317 317
 
318 318
 	// allow some time to stream the stats from the container
319 319
 	time.Sleep(4 * time.Second)
320
-	dockerCmd(c, "rm", "-f", name)
320
+	cli.DockerCmd(c, "rm", "-f", name)
321 321
 
322 322
 	// collect the results from the stats stream or timeout and fail
323 323
 	// if the stream was not disconnected.
... ...
@@ -335,8 +333,8 @@ func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) {
335 335
 }
336 336
 
337 337
 func (s *DockerAPISuite) TestGetStoppedContainerStats(c *testing.T) {
338
-	name := "statscontainer"
339
-	dockerCmd(c, "create", "--name", name, "busybox", "ps")
338
+	const name = "statscontainer3"
339
+	cli.DockerCmd(c, "create", "--name", name, "busybox", "ps")
340 340
 
341 341
 	chResp := make(chan error, 1)
342 342
 
... ...
@@ -394,9 +392,9 @@ func (s *DockerAPISuite) TestContainerAPIPause(c *testing.T) {
394 394
 
395 395
 func (s *DockerAPISuite) TestContainerAPITop(c *testing.T) {
396 396
 	testRequires(c, DaemonIsLinux)
397
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top && true")
397
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top && true").Stdout()
398 398
 	id := strings.TrimSpace(out)
399
-	assert.NilError(c, waitRun(id))
399
+	cli.WaitRun(c, id)
400 400
 
401 401
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
402 402
 	assert.NilError(c, err)
... ...
@@ -417,9 +415,8 @@ func (s *DockerAPISuite) TestContainerAPITop(c *testing.T) {
417 417
 
418 418
 func (s *DockerAPISuite) TestContainerAPITopWindows(c *testing.T) {
419 419
 	testRequires(c, DaemonIsWindows)
420
-	out := runSleepingContainer(c, "-d")
421
-	id := strings.TrimSpace(out)
422
-	assert.NilError(c, waitRun(id))
420
+	id := runSleepingContainer(c, "-d")
421
+	cli.WaitRun(c, id)
423 422
 
424 423
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
425 424
 	assert.NilError(c, err)
... ...
@@ -447,8 +444,8 @@ func (s *DockerAPISuite) TestContainerAPITopWindows(c *testing.T) {
447 447
 }
448 448
 
449 449
 func (s *DockerAPISuite) TestContainerAPICommit(c *testing.T) {
450
-	cName := "testapicommit"
451
-	dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
450
+	const cName = "testapicommit"
451
+	cli.DockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
452 452
 
453 453
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
454 454
 	assert.NilError(c, err)
... ...
@@ -465,12 +462,12 @@ func (s *DockerAPISuite) TestContainerAPICommit(c *testing.T) {
465 465
 	assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd))
466 466
 
467 467
 	// sanity check, make sure the image is what we think it is
468
-	dockerCmd(c, "run", img.ID, "ls", "/test")
468
+	cli.DockerCmd(c, "run", img.ID, "ls", "/test")
469 469
 }
470 470
 
471 471
 func (s *DockerAPISuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) {
472
-	cName := "testapicommitwithconfig"
473
-	dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
472
+	const cName = "testapicommitwithconfig"
473
+	cli.DockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
474 474
 
475 475
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
476 476
 	assert.NilError(c, err)
... ...
@@ -498,7 +495,7 @@ func (s *DockerAPISuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) {
498 498
 	assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd))
499 499
 
500 500
 	// sanity check, make sure the image is what we think it is
501
-	dockerCmd(c, "run", img.ID, "ls", "/test")
501
+	cli.DockerCmd(c, "run", img.ID, "ls", "/test")
502 502
 }
503 503
 
504 504
 func (s *DockerAPISuite) TestContainerAPIBadPort(c *testing.T) {
... ...
@@ -542,7 +539,7 @@ func (s *DockerAPISuite) TestContainerAPICreate(c *testing.T) {
542 542
 	ctr, err := apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "")
543 543
 	assert.NilError(c, err)
544 544
 
545
-	out, _ := dockerCmd(c, "start", "-a", ctr.ID)
545
+	out := cli.DockerCmd(c, "start", "-a", ctr.ID).Stdout()
546 546
 	assert.Equal(c, strings.TrimSpace(out), "/test")
547 547
 }
548 548
 
... ...
@@ -848,10 +845,9 @@ func (s *DockerAPISuite) TestCreateWithTooLowMemoryLimit(c *testing.T) {
848 848
 }
849 849
 
850 850
 func (s *DockerAPISuite) TestContainerAPIRename(c *testing.T) {
851
-	out, _ := dockerCmd(c, "run", "--name", "TestContainerAPIRename", "-d", "busybox", "sh")
852
-
851
+	out := cli.DockerCmd(c, "run", "--name", "TestContainerAPIRename", "-d", "busybox", "sh").Stdout()
853 852
 	containerID := strings.TrimSpace(out)
854
-	newName := "TestContainerAPIRenameNew"
853
+	const newName = "TestContainerAPIRenameNew"
855 854
 
856 855
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
857 856
 	assert.NilError(c, err)
... ...
@@ -865,7 +861,7 @@ func (s *DockerAPISuite) TestContainerAPIRename(c *testing.T) {
865 865
 }
866 866
 
867 867
 func (s *DockerAPISuite) TestContainerAPIKill(c *testing.T) {
868
-	name := "test-api-kill"
868
+	const name = "test-api-kill"
869 869
 	runSleepingContainer(c, "-i", "--name", name)
870 870
 
871 871
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
... ...
@@ -880,7 +876,7 @@ func (s *DockerAPISuite) TestContainerAPIKill(c *testing.T) {
880 880
 }
881 881
 
882 882
 func (s *DockerAPISuite) TestContainerAPIRestart(c *testing.T) {
883
-	name := "test-api-restart"
883
+	const name = "test-api-restart"
884 884
 	runSleepingContainer(c, "-di", "--name", name)
885 885
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
886 886
 	assert.NilError(c, err)
... ...
@@ -894,10 +890,9 @@ func (s *DockerAPISuite) TestContainerAPIRestart(c *testing.T) {
894 894
 }
895 895
 
896 896
 func (s *DockerAPISuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) {
897
-	name := "test-api-restart-no-timeout-param"
898
-	out := runSleepingContainer(c, "-di", "--name", name)
899
-	id := strings.TrimSpace(out)
900
-	assert.NilError(c, waitRun(id))
897
+	const name = "test-api-restart-no-timeout-param"
898
+	id := runSleepingContainer(c, "-di", "--name", name)
899
+	cli.WaitRun(c, id)
901 900
 
902 901
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
903 902
 	assert.NilError(c, err)
... ...
@@ -910,7 +905,7 @@ func (s *DockerAPISuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) {
910 910
 }
911 911
 
912 912
 func (s *DockerAPISuite) TestContainerAPIStart(c *testing.T) {
913
-	name := "testing-start"
913
+	const name = "testing-start"
914 914
 	config := container.Config{
915 915
 		Image:     "busybox",
916 916
 		Cmd:       append([]string{"/bin/sh", "-c"}, sleepCommandForDaemonPlatform()...),
... ...
@@ -936,7 +931,7 @@ func (s *DockerAPISuite) TestContainerAPIStart(c *testing.T) {
936 936
 }
937 937
 
938 938
 func (s *DockerAPISuite) TestContainerAPIStop(c *testing.T) {
939
-	name := "test-api-stop"
939
+	const name = "test-api-stop"
940 940
 	runSleepingContainer(c, "-i", "--name", name)
941 941
 	timeout := 30
942 942
 
... ...
@@ -959,13 +954,13 @@ func (s *DockerAPISuite) TestContainerAPIStop(c *testing.T) {
959 959
 }
960 960
 
961 961
 func (s *DockerAPISuite) TestContainerAPIWait(c *testing.T) {
962
-	name := "test-api-wait"
962
+	const name = "test-api-wait"
963 963
 
964 964
 	sleepCmd := "/bin/sleep"
965 965
 	if testEnv.DaemonInfo.OSType == "windows" {
966 966
 		sleepCmd = "sleep"
967 967
 	}
968
-	dockerCmd(c, "run", "--name", name, "busybox", sleepCmd, "2")
968
+	cli.DockerCmd(c, "run", "--name", name, "busybox", sleepCmd, "2")
969 969
 
970 970
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
971 971
 	assert.NilError(c, err)
... ...
@@ -982,8 +977,8 @@ func (s *DockerAPISuite) TestContainerAPIWait(c *testing.T) {
982 982
 }
983 983
 
984 984
 func (s *DockerAPISuite) TestContainerAPICopyNotExistsAnyMore(c *testing.T) {
985
-	name := "test-container-api-copy"
986
-	dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
985
+	const name = "test-container-api-copy"
986
+	cli.DockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
987 987
 
988 988
 	postData := types.CopyConfig{
989 989
 		Resource: "/test.txt",
... ...
@@ -996,8 +991,8 @@ func (s *DockerAPISuite) TestContainerAPICopyNotExistsAnyMore(c *testing.T) {
996 996
 
997 997
 func (s *DockerAPISuite) TestContainerAPICopyPre124(c *testing.T) {
998 998
 	testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
999
-	name := "test-container-api-copy"
1000
-	dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
999
+	const name = "test-container-api-copy"
1000
+	cli.DockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
1001 1001
 
1002 1002
 	postData := types.CopyConfig{
1003 1003
 		Resource: "/test.txt",
... ...
@@ -1026,8 +1021,8 @@ func (s *DockerAPISuite) TestContainerAPICopyPre124(c *testing.T) {
1026 1026
 
1027 1027
 func (s *DockerAPISuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.T) {
1028 1028
 	testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
1029
-	name := "test-container-api-copy-resource-empty"
1030
-	dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
1029
+	const name = "test-container-api-copy-resource-empty"
1030
+	cli.DockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
1031 1031
 
1032 1032
 	postData := types.CopyConfig{
1033 1033
 		Resource: "",
... ...
@@ -1047,8 +1042,8 @@ func (s *DockerAPISuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.
1047 1047
 
1048 1048
 func (s *DockerAPISuite) TestContainerAPICopyResourcePathNotFoundPre124(c *testing.T) {
1049 1049
 	testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
1050
-	name := "test-container-api-copy-resource-not-found"
1051
-	dockerCmd(c, "run", "--name", name, "busybox")
1050
+	const name = "test-container-api-copy-resource-not-found"
1051
+	cli.DockerCmd(c, "run", "--name", name, "busybox")
1052 1052
 
1053 1053
 	postData := types.CopyConfig{
1054 1054
 		Resource: "/notexist",
... ...
@@ -1078,12 +1073,9 @@ func (s *DockerAPISuite) TestContainerAPICopyContainerNotFoundPr124(c *testing.T
1078 1078
 }
1079 1079
 
1080 1080
 func (s *DockerAPISuite) TestContainerAPIDelete(c *testing.T) {
1081
-	out := runSleepingContainer(c)
1082
-
1083
-	id := strings.TrimSpace(out)
1084
-	assert.NilError(c, waitRun(id))
1085
-
1086
-	dockerCmd(c, "stop", id)
1081
+	id := runSleepingContainer(c)
1082
+	cli.WaitRun(c, id)
1083
+	cli.DockerCmd(c, "stop", id)
1087 1084
 
1088 1085
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
1089 1086
 	assert.NilError(c, err)
... ...
@@ -1103,9 +1095,8 @@ func (s *DockerAPISuite) TestContainerAPIDeleteNotExist(c *testing.T) {
1103 1103
 }
1104 1104
 
1105 1105
 func (s *DockerAPISuite) TestContainerAPIDeleteForce(c *testing.T) {
1106
-	out := runSleepingContainer(c)
1107
-	id := strings.TrimSpace(out)
1108
-	assert.NilError(c, waitRun(id))
1106
+	id := runSleepingContainer(c)
1107
+	cli.WaitRun(c, id)
1109 1108
 
1110 1109
 	removeOptions := container.RemoveOptions{
1111 1110
 		Force: true,
... ...
@@ -1122,15 +1113,13 @@ func (s *DockerAPISuite) TestContainerAPIDeleteForce(c *testing.T) {
1122 1122
 func (s *DockerAPISuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) {
1123 1123
 	// Windows does not support links
1124 1124
 	testRequires(c, DaemonIsLinux)
1125
-	out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top")
1126
-
1125
+	out := cli.DockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top").Stdout()
1127 1126
 	id := strings.TrimSpace(out)
1128
-	assert.NilError(c, waitRun(id))
1129
-
1130
-	out, _ = dockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
1127
+	cli.WaitRun(c, id)
1131 1128
 
1129
+	out = cli.DockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top").Stdout()
1132 1130
 	id2 := strings.TrimSpace(out)
1133
-	assert.Assert(c, waitRun(id2) == nil)
1131
+	cli.WaitRun(c, id2)
1134 1132
 
1135 1133
 	links := inspectFieldJSON(c, id2, "HostConfig.Links")
1136 1134
 	assert.Equal(c, links, `["/tlink1:/tlink2/tlink1"]`, "expected to have links between containers")
... ...
@@ -1158,10 +1147,8 @@ func (s *DockerAPISuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) {
1158 1158
 		vol = `c:\testvolume`
1159 1159
 	}
1160 1160
 
1161
-	out := runSleepingContainer(c, "-v", vol)
1162
-
1163
-	id := strings.TrimSpace(out)
1164
-	assert.NilError(c, waitRun(id))
1161
+	id := runSleepingContainer(c, "-v", vol)
1162
+	cli.WaitRun(c, id)
1165 1163
 
1166 1164
 	source, err := inspectMountSourceField(id, vol)
1167 1165
 	assert.NilError(c, err)
... ...
@@ -1205,10 +1192,8 @@ func (s *DockerAPISuite) TestContainerAPIChunkedEncoding(c *testing.T) {
1205 1205
 }
1206 1206
 
1207 1207
 func (s *DockerAPISuite) TestContainerAPIPostContainerStop(c *testing.T) {
1208
-	out := runSleepingContainer(c)
1209
-
1210
-	containerID := strings.TrimSpace(out)
1211
-	assert.Assert(c, waitRun(containerID) == nil)
1208
+	containerID := runSleepingContainer(c)
1209
+	cli.WaitRun(c, containerID)
1212 1210
 
1213 1211
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
1214 1212
 	assert.NilError(c, err)
... ...
@@ -1233,7 +1218,7 @@ func (s *DockerAPISuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c
1233 1233
 
1234 1234
 	_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "echotest")
1235 1235
 	assert.NilError(c, err)
1236
-	out, _ := dockerCmd(c, "start", "-a", "echotest")
1236
+	out := cli.DockerCmd(c, "start", "-a", "echotest").Combined()
1237 1237
 	assert.Equal(c, strings.TrimSpace(out), "hello world")
1238 1238
 
1239 1239
 	config2 := struct {
... ...
@@ -1243,7 +1228,7 @@ func (s *DockerAPISuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c
1243 1243
 	}{"busybox", "echo", []string{"hello", "world"}}
1244 1244
 	_, _, err = request.Post(testutil.GetContext(c), "/containers/create?name=echotest2", request.JSONBody(config2))
1245 1245
 	assert.NilError(c, err)
1246
-	out, _ = dockerCmd(c, "start", "-a", "echotest2")
1246
+	out = cli.DockerCmd(c, "start", "-a", "echotest2").Combined()
1247 1247
 	assert.Equal(c, strings.TrimSpace(out), "hello world")
1248 1248
 }
1249 1249
 
... ...
@@ -1260,7 +1245,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing
1260 1260
 
1261 1261
 	_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "echotest")
1262 1262
 	assert.NilError(c, err)
1263
-	out, _ := dockerCmd(c, "start", "-a", "echotest")
1263
+	out := cli.DockerCmd(c, "start", "-a", "echotest").Combined()
1264 1264
 	assert.Equal(c, strings.TrimSpace(out), "hello world")
1265 1265
 
1266 1266
 	config2 := struct {
... ...
@@ -1270,7 +1255,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing
1270 1270
 	}{"busybox", "echo", "hello world"}
1271 1271
 	_, _, err = request.Post(testutil.GetContext(c), "/containers/create?name=echotest2", request.JSONBody(config2))
1272 1272
 	assert.NilError(c, err)
1273
-	out, _ = dockerCmd(c, "start", "-a", "echotest2")
1273
+	out = cli.DockerCmd(c, "start", "-a", "echotest2").Combined()
1274 1274
 	assert.Equal(c, strings.TrimSpace(out), "hello world")
1275 1275
 }
1276 1276
 
... ...
@@ -1364,7 +1349,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithWrongCpusetValues(c *testin
1364 1364
 			CpusetCpus: "1-42,,",
1365 1365
 		},
1366 1366
 	}
1367
-	name := "wrong-cpuset-cpus"
1367
+	const name = "wrong-cpuset-cpus"
1368 1368
 
1369 1369
 	_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig1, &network.NetworkingConfig{}, nil, name)
1370 1370
 	expected := "Invalid value 1-42,, for cpuset cpus"
... ...
@@ -1375,8 +1360,8 @@ func (s *DockerAPISuite) TestPostContainersCreateWithWrongCpusetValues(c *testin
1375 1375
 			CpusetMems: "42-3,1--",
1376 1376
 		},
1377 1377
 	}
1378
-	name = "wrong-cpuset-mems"
1379
-	_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig2, &network.NetworkingConfig{}, nil, name)
1378
+	const name2 = "wrong-cpuset-mems"
1379
+	_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig2, &network.NetworkingConfig{}, nil, name2)
1380 1380
 	expected = "Invalid value 42-3,1-- for cpuset mems"
1381 1381
 	assert.ErrorContains(c, err, expected)
1382 1382
 }
... ...
@@ -1420,7 +1405,7 @@ func (s *DockerAPISuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *tes
1420 1420
 
1421 1421
 	assert.Equal(c, containerJSON.HostConfig.ShmSize, dconfig.DefaultShmSize)
1422 1422
 
1423
-	out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
1423
+	out := cli.DockerCmd(c, "start", "-i", containerJSON.ID).Combined()
1424 1424
 	shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
1425 1425
 	if !shmRegexp.MatchString(out) {
1426 1426
 		c.Fatalf("Expected shm of 64MB in mount command, got %v", out)
... ...
@@ -1447,7 +1432,7 @@ func (s *DockerAPISuite) TestPostContainersCreateShmSizeOmitted(c *testing.T) {
1447 1447
 
1448 1448
 	assert.Equal(c, containerJSON.HostConfig.ShmSize, int64(67108864))
1449 1449
 
1450
-	out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
1450
+	out := cli.DockerCmd(c, "start", "-i", containerJSON.ID).Combined()
1451 1451
 	shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
1452 1452
 	if !shmRegexp.MatchString(out) {
1453 1453
 		c.Fatalf("Expected shm of 64MB in mount command, got %v", out)
... ...
@@ -1478,7 +1463,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithShmSize(c *testing.T) {
1478 1478
 
1479 1479
 	assert.Equal(c, containerJSON.HostConfig.ShmSize, int64(1073741824))
1480 1480
 
1481
-	out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
1481
+	out := cli.DockerCmd(c, "start", "-i", containerJSON.ID).Combined()
1482 1482
 	shmRegex := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=1048576k`)
1483 1483
 	if !shmRegex.MatchString(out) {
1484 1484
 		c.Fatalf("Expected shm of 1GB in mount command, got %v", out)
... ...
@@ -1526,7 +1511,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *
1526 1526
 	assert.NilError(c, err)
1527 1527
 	defer apiClient.Close()
1528 1528
 
1529
-	name := "oomscoreadj-over"
1529
+	const name = "oomscoreadj-over"
1530 1530
 	_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, name)
1531 1531
 
1532 1532
 	expected := "Invalid value 1001, range for oom score adj is [-1000, 1000]"
... ...
@@ -1536,8 +1521,8 @@ func (s *DockerAPISuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *
1536 1536
 		OomScoreAdj: -1001,
1537 1537
 	}
1538 1538
 
1539
-	name = "oomscoreadj-low"
1540
-	_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, name)
1539
+	const name2 = "oomscoreadj-low"
1540
+	_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, name2)
1541 1541
 
1542 1542
 	expected = "Invalid value -1001, range for oom score adj is [-1000, 1000]"
1543 1543
 	assert.ErrorContains(c, err, expected)
... ...
@@ -1557,7 +1542,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T)
1557 1557
 	// Problematic on Windows as Windows does not support stats
1558 1558
 	testRequires(c, DaemonIsLinux)
1559 1559
 
1560
-	name := "testing-network-disabled"
1560
+	const name = "testing-network-disabled"
1561 1561
 
1562 1562
 	config := container.Config{
1563 1563
 		Image:           "busybox",
... ...
@@ -1574,8 +1559,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T)
1574 1574
 
1575 1575
 	err = apiClient.ContainerStart(testutil.GetContext(c), name, container.StartOptions{})
1576 1576
 	assert.NilError(c, err)
1577
-
1578
-	assert.Assert(c, waitRun(name) == nil)
1577
+	cli.WaitRun(c, name)
1579 1578
 
1580 1579
 	type b struct {
1581 1580
 		stats types.ContainerStats
... ...
@@ -1589,7 +1573,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T)
1589 1589
 
1590 1590
 	// allow some time to stream the stats from the container
1591 1591
 	time.Sleep(4 * time.Second)
1592
-	dockerCmd(c, "rm", "-f", name)
1592
+	cli.DockerCmd(c, "rm", "-f", name)
1593 1593
 
1594 1594
 	// collect the results from the stats stream or timeout and fail
1595 1595
 	// if the stream was not disconnected.
... ...
@@ -1943,7 +1927,7 @@ func (s *DockerAPISuite) TestContainerAPICreateMountsBindRead(c *testing.T) {
1943 1943
 	_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, "test")
1944 1944
 	assert.NilError(c, err)
1945 1945
 
1946
-	out, _ := dockerCmd(c, "start", "-a", "test")
1946
+	out := cli.DockerCmd(c, "start", "-a", "test").Combined()
1947 1947
 	assert.Equal(c, out, "hello")
1948 1948
 }
1949 1949
 
... ...
@@ -2197,7 +2181,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsTmpfs(c *testing.T) {
2197 2197
 
2198 2198
 		_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, cName)
2199 2199
 		assert.NilError(c, err)
2200
-		out, _ := dockerCmd(c, "start", "-a", cName)
2200
+		out := cli.DockerCmd(c, "start", "-a", cName).Combined()
2201 2201
 		for _, option := range x.expectedOptions {
2202 2202
 			assert.Assert(c, strings.Contains(out, option))
2203 2203
 		}
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"testing"
12 12
 
13 13
 	"github.com/docker/docker/api/types/versions"
14
+	"github.com/docker/docker/integration-cli/cli"
14 15
 	"github.com/docker/docker/testutil"
15 16
 	"github.com/docker/docker/testutil/request"
16 17
 	"github.com/pkg/errors"
... ...
@@ -19,7 +20,7 @@ import (
19 19
 
20 20
 func (s *DockerAPISuite) TestExecResizeAPIHeightWidthNoInt(c *testing.T) {
21 21
 	testRequires(c, DaemonIsLinux)
22
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
22
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "top").Stdout()
23 23
 	cleanedContainerID := strings.TrimSpace(out)
24 24
 
25 25
 	endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
... ...
@@ -35,7 +36,7 @@ func (s *DockerAPISuite) TestExecResizeAPIHeightWidthNoInt(c *testing.T) {
35 35
 // Part of #14845
36 36
 func (s *DockerAPISuite) TestExecResizeImmediatelyAfterExecStart(c *testing.T) {
37 37
 	name := "exec_resize_test"
38
-	dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")
38
+	cli.DockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")
39 39
 
40 40
 	testExecResize := func() error {
41 41
 		data := map[string]interface{}{
... ...
@@ -16,6 +16,7 @@ import (
16 16
 	"github.com/docker/docker/api/types/versions"
17 17
 	"github.com/docker/docker/client"
18 18
 	"github.com/docker/docker/integration-cli/checker"
19
+	"github.com/docker/docker/integration-cli/cli"
19 20
 	"github.com/docker/docker/testutil"
20 21
 	"github.com/docker/docker/testutil/request"
21 22
 	"gotest.tools/v3/assert"
... ...
@@ -26,7 +27,7 @@ import (
26 26
 // Regression test for #9414
27 27
 func (s *DockerAPISuite) TestExecAPICreateNoCmd(c *testing.T) {
28 28
 	name := "exec_test"
29
-	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
29
+	cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
30 30
 
31 31
 	res, body, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": nil}))
32 32
 	assert.NilError(c, err)
... ...
@@ -42,7 +43,7 @@ func (s *DockerAPISuite) TestExecAPICreateNoCmd(c *testing.T) {
42 42
 
43 43
 func (s *DockerAPISuite) TestExecAPICreateNoValidContentType(c *testing.T) {
44 44
 	name := "exec_test"
45
-	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
45
+	cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
46 46
 
47 47
 	jsonData := bytes.NewBuffer(nil)
48 48
 	if err := json.NewEncoder(jsonData).Encode(map[string]interface{}{"Cmd": nil}); err != nil {
... ...
@@ -65,9 +66,9 @@ func (s *DockerAPISuite) TestExecAPICreateContainerPaused(c *testing.T) {
65 65
 	// Not relevant on Windows as Windows containers cannot be paused
66 66
 	testRequires(c, DaemonIsLinux)
67 67
 	name := "exec_create_test"
68
-	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
68
+	cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
69 69
 
70
-	dockerCmd(c, "pause", name)
70
+	cli.DockerCmd(c, "pause", name)
71 71
 
72 72
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
73 73
 	assert.NilError(c, err)
... ...
@@ -82,7 +83,7 @@ func (s *DockerAPISuite) TestExecAPICreateContainerPaused(c *testing.T) {
82 82
 
83 83
 func (s *DockerAPISuite) TestExecAPIStart(c *testing.T) {
84 84
 	testRequires(c, DaemonIsLinux) // Uses pause/unpause but bits may be salvageable to Windows to Windows CI
85
-	dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
85
+	cli.DockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
86 86
 
87 87
 	id := createExec(c, "test")
88 88
 	startExec(c, id, http.StatusOK)
... ...
@@ -92,24 +93,24 @@ func (s *DockerAPISuite) TestExecAPIStart(c *testing.T) {
92 92
 	assert.Assert(c, execJSON.PID > 1)
93 93
 
94 94
 	id = createExec(c, "test")
95
-	dockerCmd(c, "stop", "test")
95
+	cli.DockerCmd(c, "stop", "test")
96 96
 
97 97
 	startExec(c, id, http.StatusNotFound)
98 98
 
99
-	dockerCmd(c, "start", "test")
99
+	cli.DockerCmd(c, "start", "test")
100 100
 	startExec(c, id, http.StatusNotFound)
101 101
 
102 102
 	// make sure exec is created before pausing
103 103
 	id = createExec(c, "test")
104
-	dockerCmd(c, "pause", "test")
104
+	cli.DockerCmd(c, "pause", "test")
105 105
 	startExec(c, id, http.StatusConflict)
106
-	dockerCmd(c, "unpause", "test")
106
+	cli.DockerCmd(c, "unpause", "test")
107 107
 	startExec(c, id, http.StatusOK)
108 108
 }
109 109
 
110 110
 func (s *DockerAPISuite) TestExecAPIStartEnsureHeaders(c *testing.T) {
111 111
 	testRequires(c, DaemonIsLinux)
112
-	dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
112
+	cli.DockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
113 113
 
114 114
 	id := createExec(c, "test")
115 115
 	resp, _, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON)
... ...
@@ -177,7 +178,7 @@ func (s *DockerAPISuite) TestExecAPIStartWithDetach(c *testing.T) {
177 177
 // #30311
178 178
 func (s *DockerAPISuite) TestExecAPIStartValidCommand(c *testing.T) {
179 179
 	name := "exec_test"
180
-	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
180
+	cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
181 181
 
182 182
 	id := createExecCmd(c, name, "true")
183 183
 	startExec(c, id, http.StatusOK)
... ...
@@ -194,7 +195,7 @@ func (s *DockerAPISuite) TestExecAPIStartValidCommand(c *testing.T) {
194 194
 // #30311
195 195
 func (s *DockerAPISuite) TestExecAPIStartInvalidCommand(c *testing.T) {
196 196
 	name := "exec_test"
197
-	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
197
+	cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
198 198
 
199 199
 	id := createExecCmd(c, name, "invalid")
200 200
 	if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
... ...
@@ -217,7 +218,7 @@ func (s *DockerAPISuite) TestExecStateCleanup(c *testing.T) {
217 217
 	// This test checks accidental regressions. Not part of stable API.
218 218
 
219 219
 	name := "exec_cleanup"
220
-	cid, _ := dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
220
+	cid := cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh").Stdout()
221 221
 	cid = strings.TrimSpace(cid)
222 222
 
223 223
 	stateDir := "/var/run/docker/containerd/" + cid
... ...
@@ -246,7 +247,7 @@ func (s *DockerAPISuite) TestExecStateCleanup(c *testing.T) {
246 246
 
247 247
 	poll.WaitOn(c, pollCheck(c, checkReadDir, checker.Equals(len(fi))), poll.WithTimeout(5*time.Second))
248 248
 
249
-	dockerCmd(c, "stop", name)
249
+	cli.DockerCmd(c, "stop", name)
250 250
 	_, err = os.Stat(stateDir)
251 251
 	assert.ErrorContains(c, err, "")
252 252
 	assert.Assert(c, os.IsNotExist(err))
... ...
@@ -26,7 +26,7 @@ func (s *DockerAPISuite) TestAPIImagesSaveAndLoad(c *testing.T) {
26 26
 	defer body.Close()
27 27
 	assert.Equal(c, res.StatusCode, http.StatusOK)
28 28
 
29
-	dockerCmd(c, "rmi", id)
29
+	cli.DockerCmd(c, "rmi", id)
30 30
 
31 31
 	res, loadBody, err := request.Post(ctx, "/images/load", request.RawContent(body), request.ContentType("application/x-tar"))
32 32
 	assert.NilError(c, err)
... ...
@@ -49,7 +49,7 @@ func (s *DockerAPISuite) TestAPIImagesDelete(c *testing.T) {
49 49
 	buildImageSuccessfully(c, name, build.WithDockerfile("FROM busybox\nENV FOO bar"))
50 50
 	id := getIDByName(c, name)
51 51
 
52
-	dockerCmd(c, "tag", name, "test:tag1")
52
+	cli.DockerCmd(c, "tag", name, "test:tag1")
53 53
 
54 54
 	_, err = apiClient.ImageRemove(testutil.GetContext(c), id, types.ImageRemoveOptions{})
55 55
 	assert.ErrorContains(c, err, "unable to delete")
... ...
@@ -8,15 +8,16 @@ import (
8 8
 	"github.com/docker/docker/api/types"
9 9
 	"github.com/docker/docker/api/types/versions/v1p20"
10 10
 	"github.com/docker/docker/client"
11
+	"github.com/docker/docker/integration-cli/cli"
11 12
 	"github.com/docker/docker/testutil"
12 13
 	"gotest.tools/v3/assert"
13 14
 	is "gotest.tools/v3/assert/cmp"
14 15
 )
15 16
 
16 17
 func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) {
17
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
18
-
18
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
19 19
 	cleanedContainerID := strings.TrimSpace(out)
20
+
20 21
 	keysBase := []string{
21 22
 		"Id", "State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings",
22 23
 		"ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "MountLabel", "ProcessLabel", "GraphDriver",
... ...
@@ -61,8 +62,7 @@ func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) {
61 61
 func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T) {
62 62
 	// No legacy implications for Windows
63 63
 	testRequires(c, DaemonIsLinux)
64
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
65
-
64
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
66 65
 	cleanedContainerID := strings.TrimSpace(out)
67 66
 
68 67
 	cases := []string{"v1.19", "v1.20"}
... ...
@@ -82,8 +82,7 @@ func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T)
82 82
 }
83 83
 
84 84
 func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriver(c *testing.T) {
85
-	out, _ := dockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true")
86
-
85
+	out := cli.DockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true").Stdout()
87 86
 	cleanedContainerID := strings.TrimSpace(out)
88 87
 
89 88
 	body := getInspectBody(c, "v1.25", cleanedContainerID)
... ...
@@ -106,7 +105,7 @@ func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriver(c *testing.T) {
106 106
 }
107 107
 
108 108
 func (s *DockerAPISuite) TestInspectAPIImageResponse(c *testing.T) {
109
-	dockerCmd(c, "tag", "busybox:latest", "busybox:mytag")
109
+	cli.DockerCmd(c, "tag", "busybox:latest", "busybox:mytag")
110 110
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
111 111
 	assert.NilError(c, err)
112 112
 	defer apiClient.Close()
... ...
@@ -123,8 +122,7 @@ func (s *DockerAPISuite) TestInspectAPIImageResponse(c *testing.T) {
123 123
 func (s *DockerAPISuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) {
124 124
 	// Not relevant on Windows
125 125
 	testRequires(c, DaemonIsLinux)
126
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
127
-
126
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
128 127
 	cleanedContainerID := strings.TrimSpace(out)
129 128
 
130 129
 	cases := []string{"v1.19", "v1.20"}
... ...
@@ -147,9 +145,9 @@ func (s *DockerAPISuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) {
147 147
 func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) {
148 148
 	// Not relevant on Windows, and besides it doesn't have any bridge network settings
149 149
 	testRequires(c, DaemonIsLinux)
150
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
150
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "top").Stdout()
151 151
 	containerID := strings.TrimSpace(out)
152
-	waitRun(containerID)
152
+	cli.WaitRun(c, containerID)
153 153
 
154 154
 	body := getInspectBody(c, "v1.20", containerID)
155 155
 
... ...
@@ -164,9 +162,9 @@ func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) {
164 164
 func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings121(c *testing.T) {
165 165
 	// Windows doesn't have any bridge network settings
166 166
 	testRequires(c, DaemonIsLinux)
167
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
167
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "top").Stdout()
168 168
 	containerID := strings.TrimSpace(out)
169
-	waitRun(containerID)
169
+	cli.WaitRun(c, containerID)
170 170
 
171 171
 	body := getInspectBody(c, "v1.21", containerID)
172 172
 
... ...
@@ -13,6 +13,7 @@ import (
13 13
 
14 14
 	"github.com/docker/docker/api/types/container"
15 15
 	"github.com/docker/docker/client"
16
+	"github.com/docker/docker/integration-cli/cli"
16 17
 	"github.com/docker/docker/pkg/stdcopy"
17 18
 	"github.com/docker/docker/testutil"
18 19
 	"github.com/docker/docker/testutil/request"
... ...
@@ -20,9 +21,9 @@ import (
20 20
 )
21 21
 
22 22
 func (s *DockerAPISuite) TestLogsAPIWithStdout(c *testing.T) {
23
-	out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done")
23
+	out := cli.DockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done").Stdout()
24 24
 	id := strings.TrimSpace(out)
25
-	assert.NilError(c, waitRun(id))
25
+	cli.WaitRun(c, id)
26 26
 
27 27
 	type logOut struct {
28 28
 		out string
... ...
@@ -56,8 +57,8 @@ func (s *DockerAPISuite) TestLogsAPIWithStdout(c *testing.T) {
56 56
 }
57 57
 
58 58
 func (s *DockerAPISuite) TestLogsAPINoStdoutNorStderr(c *testing.T) {
59
-	name := "logs_test"
60
-	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
59
+	const name = "logs_test"
60
+	cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
61 61
 	apiClient, err := client.NewClientWithOpts(client.FromEnv)
62 62
 	assert.NilError(c, err)
63 63
 	defer apiClient.Close()
... ...
@@ -68,9 +69,9 @@ func (s *DockerAPISuite) TestLogsAPINoStdoutNorStderr(c *testing.T) {
68 68
 
69 69
 // Regression test for #12704
70 70
 func (s *DockerAPISuite) TestLogsAPIFollowEmptyOutput(c *testing.T) {
71
-	name := "logs_test"
71
+	const name = "logs_test"
72 72
 	t0 := time.Now()
73
-	dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
73
+	cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
74 74
 
75 75
 	_, body, err := request.Get(testutil.GetContext(c), fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name))
76 76
 	t1 := time.Now()
... ...
@@ -91,21 +92,21 @@ func (s *DockerAPISuite) TestLogsAPIContainerNotFound(c *testing.T) {
91 91
 
92 92
 func (s *DockerAPISuite) TestLogsAPIUntilFutureFollow(c *testing.T) {
93 93
 	testRequires(c, DaemonIsLinux)
94
-	name := "logsuntilfuturefollow"
95
-	dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", "while true; do date +%s; sleep 1; done")
96
-	assert.NilError(c, waitRun(name))
94
+	const name = "logsuntilfuturefollow"
95
+	cli.DockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", "while true; do date +%s; sleep 1; done")
96
+	cli.WaitRun(c, name)
97 97
 
98 98
 	untilSecs := 5
99 99
 	untilDur, err := time.ParseDuration(fmt.Sprintf("%ds", untilSecs))
100 100
 	assert.NilError(c, err)
101 101
 	until := daemonTime(c).Add(untilDur)
102 102
 
103
-	client, err := client.NewClientWithOpts(client.FromEnv)
103
+	apiClient, err := client.NewClientWithOpts(client.FromEnv)
104 104
 	if err != nil {
105 105
 		c.Fatal(err)
106 106
 	}
107 107
 
108
-	reader, err := client.ContainerLogs(testutil.GetContext(c), name, container.LogsOptions{
108
+	reader, err := apiClient.ContainerLogs(testutil.GetContext(c), name, container.LogsOptions{
109 109
 		Until:      until.Format(time.RFC3339Nano),
110 110
 		Follow:     true,
111 111
 		ShowStdout: true,
... ...
@@ -163,16 +164,16 @@ func (s *DockerAPISuite) TestLogsAPIUntilFutureFollow(c *testing.T) {
163 163
 
164 164
 func (s *DockerAPISuite) TestLogsAPIUntil(c *testing.T) {
165 165
 	testRequires(c, MinimumAPIVersion("1.34"))
166
-	name := "logsuntil"
167
-	dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; sleep 1; done")
166
+	const name = "logsuntil"
167
+	cli.DockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; sleep 1; done")
168 168
 
169
-	client, err := client.NewClientWithOpts(client.FromEnv)
169
+	apiClient, err := client.NewClientWithOpts(client.FromEnv)
170 170
 	if err != nil {
171 171
 		c.Fatal(err)
172 172
 	}
173 173
 
174 174
 	extractBody := func(c *testing.T, cfg container.LogsOptions) []string {
175
-		reader, err := client.ContainerLogs(testutil.GetContext(c), name, cfg)
175
+		reader, err := apiClient.ContainerLogs(testutil.GetContext(c), name, cfg)
176 176
 		assert.NilError(c, err)
177 177
 
178 178
 		actualStdout := new(bytes.Buffer)
... ...
@@ -200,16 +201,16 @@ func (s *DockerAPISuite) TestLogsAPIUntil(c *testing.T) {
200 200
 }
201 201
 
202 202
 func (s *DockerAPISuite) TestLogsAPIUntilDefaultValue(c *testing.T) {
203
-	name := "logsuntildefaultval"
204
-	dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; done")
203
+	const name = "logsuntildefaultval"
204
+	cli.DockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; done")
205 205
 
206
-	client, err := client.NewClientWithOpts(client.FromEnv)
206
+	apiClient, err := client.NewClientWithOpts(client.FromEnv)
207 207
 	if err != nil {
208 208
 		c.Fatal(err)
209 209
 	}
210 210
 
211 211
 	extractBody := func(c *testing.T, cfg container.LogsOptions) []string {
212
-		reader, err := client.ContainerLogs(testutil.GetContext(c), name, cfg)
212
+		reader, err := apiClient.ContainerLogs(testutil.GetContext(c), name, cfg)
213 213
 		assert.NilError(c, err)
214 214
 
215 215
 		actualStdout := new(bytes.Buffer)
... ...
@@ -13,6 +13,7 @@ import (
13 13
 	"github.com/docker/docker/api/types/filters"
14 14
 	"github.com/docker/docker/api/types/network"
15 15
 	"github.com/docker/docker/api/types/versions"
16
+	"github.com/docker/docker/integration-cli/cli"
16 17
 	"github.com/docker/docker/testutil"
17 18
 	"github.com/docker/docker/testutil/request"
18 19
 	"gotest.tools/v3/assert"
... ...
@@ -40,7 +41,7 @@ func (s *DockerAPISuite) TestAPINetworkInspectBridge(c *testing.T) {
40 40
 	assert.Equal(c, nr.Name, "bridge")
41 41
 
42 42
 	// run a container and attach it to the default bridge network
43
-	out, _ := dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
43
+	out := cli.DockerCmd(c, "run", "-d", "--name", "test", "busybox", "top").Stdout()
44 44
 	containerID := strings.TrimSpace(out)
45 45
 	containerIP := findContainerIP(c, "test", "bridge")
46 46
 
... ...
@@ -104,7 +105,7 @@ func (s *DockerAPISuite) TestAPINetworkConnectDisconnect(c *testing.T) {
104 104
 	assert.Equal(c, len(nr.Containers), 0)
105 105
 
106 106
 	// run a container
107
-	out, _ := dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
107
+	out := cli.DockerCmd(c, "run", "-d", "--name", "test", "busybox", "top").Stdout()
108 108
 	containerID := strings.TrimSpace(out)
109 109
 
110 110
 	// connect the container to the test network
... ...
@@ -16,6 +16,7 @@ import (
16 16
 	"github.com/docker/docker/api/types/system"
17 17
 	"github.com/docker/docker/api/types/versions"
18 18
 	"github.com/docker/docker/client"
19
+	"github.com/docker/docker/integration-cli/cli"
19 20
 	"github.com/docker/docker/testutil"
20 21
 	"github.com/docker/docker/testutil/request"
21 22
 	"gotest.tools/v3/assert"
... ...
@@ -26,10 +27,9 @@ var expectedNetworkInterfaceStats = strings.Split("rx_bytes rx_dropped rx_errors
26 26
 
27 27
 func (s *DockerAPISuite) TestAPIStatsNoStreamGetCpu(c *testing.T) {
28 28
 	skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination")
29
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;usleep 100; do echo 'Hello'; done")
30
-
29
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;usleep 100; do echo 'Hello'; done").Stdout()
31 30
 	id := strings.TrimSpace(out)
32
-	assert.NilError(c, waitRun(id))
31
+	cli.WaitRun(c, id)
33 32
 	resp, body, err := request.Get(testutil.GetContext(c), fmt.Sprintf("/containers/%s/stats?stream=false", id))
34 33
 	assert.NilError(c, err)
35 34
 	assert.Equal(c, resp.StatusCode, http.StatusOK)
... ...
@@ -66,7 +66,7 @@ func (s *DockerAPISuite) TestAPIStatsNoStreamGetCpu(c *testing.T) {
66 66
 }
67 67
 
68 68
 func (s *DockerAPISuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T) {
69
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1")
69
+	out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1").Stdout()
70 70
 	id := strings.TrimSpace(out)
71 71
 
72 72
 	getGoRoutines := func() int {
... ...
@@ -104,9 +104,8 @@ func (s *DockerAPISuite) TestAPIStatsNetworkStats(c *testing.T) {
104 104
 	skip.If(c, RuntimeIsWindowsContainerd(), "FIXME: Broken on Windows + containerd combination")
105 105
 	testRequires(c, testEnv.IsLocalDaemon)
106 106
 
107
-	out := runSleepingContainer(c)
108
-	id := strings.TrimSpace(out)
109
-	assert.NilError(c, waitRun(id))
107
+	id := runSleepingContainer(c)
108
+	cli.WaitRun(c, id)
110 109
 
111 110
 	// Retrieve the container address
112 111
 	net := "bridge"
... ...
@@ -170,9 +169,8 @@ func (s *DockerAPISuite) TestAPIStatsNetworkStatsVersioning(c *testing.T) {
170 170
 	// Windows doesn't support API versions less than 1.25, so no point testing 1.17 .. 1.21
171 171
 	testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
172 172
 
173
-	out := runSleepingContainer(c)
174
-	id := strings.TrimSpace(out)
175
-	assert.NilError(c, waitRun(id))
173
+	id := runSleepingContainer(c)
174
+	cli.WaitRun(c, id)
176 175
 	wg := sync.WaitGroup{}
177 176
 
178 177
 	for i := 17; i <= 21; i++ {
... ...
@@ -278,13 +276,11 @@ func (s *DockerAPISuite) TestAPIStatsContainerNotFound(c *testing.T) {
278 278
 func (s *DockerAPISuite) TestAPIStatsNoStreamConnectedContainers(c *testing.T) {
279 279
 	testRequires(c, DaemonIsLinux)
280 280
 
281
-	out1 := runSleepingContainer(c)
282
-	id1 := strings.TrimSpace(out1)
283
-	assert.NilError(c, waitRun(id1))
281
+	id1 := runSleepingContainer(c)
282
+	cli.WaitRun(c, id1)
284 283
 
285
-	out2 := runSleepingContainer(c, "--net", "container:"+id1)
286
-	id2 := strings.TrimSpace(out2)
287
-	assert.NilError(c, waitRun(id2))
284
+	id2 := runSleepingContainer(c, "--net", "container:"+id1)
285
+	cli.WaitRun(c, id2)
288 286
 
289 287
 	ch := make(chan error, 1)
290 288
 	go func() {
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"testing"
10 10
 
11 11
 	"github.com/docker/docker/api/types/versions"
12
+	"github.com/docker/docker/integration-cli/cli"
12 13
 	"github.com/docker/docker/testutil"
13 14
 	"github.com/docker/docker/testutil/request"
14 15
 	"gotest.tools/v3/assert"
... ...
@@ -21,7 +22,7 @@ func formatV123StartAPIURL(url string) string {
21 21
 
22 22
 func (s *DockerAPISuite) TestDeprecatedContainerAPIStartHostConfig(c *testing.T) {
23 23
 	name := "test-deprecated-api-124"
24
-	dockerCmd(c, "create", "--name", name, "busybox")
24
+	cli.DockerCmd(c, "create", "--name", name, "busybox")
25 25
 	config := map[string]interface{}{
26 26
 		"Binds": []string{"/aa:/bb"},
27 27
 	}
... ...
@@ -108,7 +109,7 @@ func (s *DockerAPISuite) TestDeprecatedContainerAPIStartVolumesFrom(c *testing.T
108 108
 	volName := "voltst"
109 109
 	volPath := "/tmp"
110 110
 
111
-	dockerCmd(c, "run", "--name", volName, "-v", volPath, "busybox")
111
+	cli.DockerCmd(c, "run", "--name", volName, "-v", volPath, "busybox")
112 112
 
113 113
 	name := "TestContainerAPIStartVolumesFrom"
114 114
 	config := map[string]interface{}{
... ...
@@ -138,12 +139,12 @@ func (s *DockerAPISuite) TestDeprecatedContainerAPIStartVolumesFrom(c *testing.T
138 138
 func (s *DockerAPISuite) TestDeprecatedPostContainerBindNormalVolume(c *testing.T) {
139 139
 	// TODO Windows to Windows CI - Port this
140 140
 	testRequires(c, DaemonIsLinux)
141
-	dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox")
141
+	cli.DockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox")
142 142
 
143 143
 	fooDir, err := inspectMountSourceField("one", "/foo")
144 144
 	assert.NilError(c, err)
145 145
 
146
-	dockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox")
146
+	cli.DockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox")
147 147
 
148 148
 	bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
149 149
 	res, _, err := request.Post(testutil.GetContext(c), formatV123StartAPIURL("/containers/two/start"), request.JSONBody(bindSpec))
... ...
@@ -158,11 +159,10 @@ func (s *DockerAPISuite) TestDeprecatedPostContainerBindNormalVolume(c *testing.
158 158
 func (s *DockerAPISuite) TestDeprecatedStartWithTooLowMemoryLimit(c *testing.T) {
159 159
 	// TODO Windows: Port once memory is supported
160 160
 	testRequires(c, DaemonIsLinux)
161
-	out, _ := dockerCmd(c, "create", "busybox")
161
+	containerID := cli.DockerCmd(c, "create", "busybox").Stdout()
162
+	containerID = strings.TrimSpace(containerID)
162 163
 
163
-	containerID := strings.TrimSpace(out)
164
-
165
-	config := `{
164
+	const config = `{
166 165
                 "CpuShares": 100,
167 166
                 "Memory":    524287
168 167
         }`
... ...
@@ -185,7 +185,7 @@ func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithoutLinksInHostConf
185 185
 	// An alternate test could be written to validate the negative testing aspect of this
186 186
 	testRequires(c, DaemonIsLinux)
187 187
 	name := "test-host-config-links"
188
-	dockerCmd(c, append([]string{"create", "--name", name, "busybox"}, sleepCommandForDaemonPlatform()...)...)
188
+	cli.DockerCmd(c, append([]string{"create", "--name", name, "busybox"}, sleepCommandForDaemonPlatform()...)...)
189 189
 
190 190
 	hc := inspectFieldJSON(c, name, "HostConfig")
191 191
 	config := `{"HostConfig":` + hc + `}`
... ...
@@ -202,8 +202,8 @@ func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(
202 202
 	// An alternate test could be written to validate the negative testing aspect of this
203 203
 	testRequires(c, DaemonIsLinux)
204 204
 	name := "test-host-config-links"
205
-	dockerCmd(c, "run", "--name", "foo", "-d", "busybox", "top")
206
-	dockerCmd(c, "create", "--name", name, "--link", "foo:bar", "busybox", "top")
205
+	cli.DockerCmd(c, "run", "--name", "foo", "-d", "busybox", "top")
206
+	cli.DockerCmd(c, "create", "--name", name, "--link", "foo:bar", "busybox", "top")
207 207
 
208 208
 	hc := inspectFieldJSON(c, name, "HostConfig")
209 209
 	config := `{"HostConfig":` + hc + `}`
... ...
@@ -218,12 +218,12 @@ func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(
218 218
 func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked(c *testing.T) {
219 219
 	// Windows does not support links
220 220
 	testRequires(c, DaemonIsLinux)
221
-	name := "test-host-config-links"
222
-	out, _ := dockerCmd(c, "run", "--name", "link0", "-d", "busybox", "top")
223
-	defer dockerCmd(c, "stop", "link0")
224
-	id := strings.TrimSpace(out)
225
-	dockerCmd(c, "create", "--name", name, "--link", id, "busybox", "top")
226
-	defer dockerCmd(c, "stop", name)
221
+	const name = "test-host-config-links"
222
+	containerID := cli.DockerCmd(c, "run", "--name", "link0", "-d", "busybox", "top").Combined()
223
+	containerID = strings.TrimSpace(containerID)
224
+	defer cli.DockerCmd(c, "stop", "link0")
225
+	cli.DockerCmd(c, "create", "--name", name, "--link", containerID, "busybox", "top")
226
+	defer cli.DockerCmd(c, "stop", name)
227 227
 
228 228
 	hc := inspectFieldJSON(c, name, "HostConfig")
229 229
 	config := `{"HostConfig":` + hc + `}`
... ...
@@ -237,10 +237,10 @@ func (s *DockerAPISuite) TestDeprecatedPostContainersStartWithLinksInHostConfigI
237 237
 func (s *DockerAPISuite) TestDeprecatedStartWithNilDNS(c *testing.T) {
238 238
 	// TODO Windows: Add once DNS is supported
239 239
 	testRequires(c, DaemonIsLinux)
240
-	out, _ := dockerCmd(c, "create", "busybox")
241
-	containerID := strings.TrimSpace(out)
240
+	containerID := cli.DockerCmd(c, "create", "busybox").Stdout()
241
+	containerID = strings.TrimSpace(containerID)
242 242
 
243
-	config := `{"HostConfig": {"Dns": null}}`
243
+	const config = `{"HostConfig": {"Dns": null}}`
244 244
 
245 245
 	res, b, err := request.Post(testutil.GetContext(c), formatV123StartAPIURL("/containers/"+containerID+"/start"), request.RawString(config), request.JSON)
246 246
 	assert.NilError(c, err)