Browse code

integration-cli: DockerCLICpSuite: replace dockerCmd

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

Sebastiaan van Stijn authored on 2023/07/28 02:59:33
Showing 3 changed files
... ...
@@ -12,6 +12,7 @@ import (
12 12
 	"strings"
13 13
 	"testing"
14 14
 
15
+	"github.com/docker/docker/integration-cli/cli"
15 16
 	"gotest.tools/v3/assert"
16 17
 	is "gotest.tools/v3/assert/cmp"
17 18
 	"gotest.tools/v3/icmd"
... ...
@@ -48,11 +49,10 @@ func (s *DockerCLICpSuite) TestCpLocalOnly(c *testing.T) {
48 48
 // Test for #5656
49 49
 // Check that garbage paths don't escape the container's rootfs
50 50
 func (s *DockerCLICpSuite) TestCpGarbagePath(c *testing.T) {
51
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
51
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath).Stdout()
52
+	containerID = strings.TrimSpace(containerID)
52 53
 
53
-	containerID := strings.TrimSpace(out)
54
-
55
-	out, _ = dockerCmd(c, "wait", containerID)
54
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
56 55
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
57 56
 	assert.NilError(c, os.MkdirAll(cpTestPath, os.ModeDir))
58 57
 
... ...
@@ -69,9 +69,8 @@ func (s *DockerCLICpSuite) TestCpGarbagePath(c *testing.T) {
69 69
 	tmpname := filepath.Join(tmpdir, cpTestName)
70 70
 	defer os.RemoveAll(tmpdir)
71 71
 
72
-	path := path.Join("../../../../../../../../../../../../", cpFullPath)
73
-
74
-	dockerCmd(c, "cp", containerID+":"+path, tmpdir)
72
+	containerPath := path.Join("../../../../../../../../../../../../", cpFullPath)
73
+	cli.DockerCmd(c, "cp", containerID+":"+containerPath, tmpdir)
75 74
 
76 75
 	file, _ := os.Open(tmpname)
77 76
 	defer file.Close()
... ...
@@ -84,11 +83,10 @@ func (s *DockerCLICpSuite) TestCpGarbagePath(c *testing.T) {
84 84
 
85 85
 // Check that relative paths are relative to the container's rootfs
86 86
 func (s *DockerCLICpSuite) TestCpRelativePath(c *testing.T) {
87
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
88
-
89
-	containerID := strings.TrimSpace(out)
87
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath).Stdout()
88
+	containerID = strings.TrimSpace(containerID)
90 89
 
91
-	out, _ = dockerCmd(c, "wait", containerID)
90
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
92 91
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
93 92
 	assert.NilError(c, os.MkdirAll(cpTestPath, os.ModeDir))
94 93
 
... ...
@@ -113,7 +111,7 @@ func (s *DockerCLICpSuite) TestCpRelativePath(c *testing.T) {
113 113
 	}
114 114
 	assert.Assert(c, path.IsAbs(cpFullPath), "path %s was assumed to be an absolute path", cpFullPath)
115 115
 
116
-	dockerCmd(c, "cp", containerID+":"+relPath, tmpdir)
116
+	cli.DockerCmd(c, "cp", containerID+":"+relPath, tmpdir)
117 117
 
118 118
 	file, _ := os.Open(tmpname)
119 119
 	defer file.Close()
... ...
@@ -126,11 +124,10 @@ func (s *DockerCLICpSuite) TestCpRelativePath(c *testing.T) {
126 126
 
127 127
 // Check that absolute paths are relative to the container's rootfs
128 128
 func (s *DockerCLICpSuite) TestCpAbsolutePath(c *testing.T) {
129
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
129
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath).Stdout()
130
+	containerID = strings.TrimSpace(containerID)
130 131
 
131
-	containerID := strings.TrimSpace(out)
132
-
133
-	out, _ = dockerCmd(c, "wait", containerID)
132
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
134 133
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
135 134
 	assert.NilError(c, os.MkdirAll(cpTestPath, os.ModeDir))
136 135
 
... ...
@@ -147,9 +144,7 @@ func (s *DockerCLICpSuite) TestCpAbsolutePath(c *testing.T) {
147 147
 	tmpname := filepath.Join(tmpdir, cpTestName)
148 148
 	defer os.RemoveAll(tmpdir)
149 149
 
150
-	path := cpFullPath
151
-
152
-	dockerCmd(c, "cp", containerID+":"+path, tmpdir)
150
+	cli.DockerCmd(c, "cp", containerID+":"+cpFullPath, tmpdir)
153 151
 
154 152
 	file, _ := os.Open(tmpname)
155 153
 	defer file.Close()
... ...
@@ -164,11 +159,10 @@ func (s *DockerCLICpSuite) TestCpAbsolutePath(c *testing.T) {
164 164
 // Check that absolute symlinks are still relative to the container's rootfs
165 165
 func (s *DockerCLICpSuite) TestCpAbsoluteSymlink(c *testing.T) {
166 166
 	testRequires(c, DaemonIsLinux)
167
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path")
167
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path").Stdout()
168
+	containerID = strings.TrimSpace(containerID)
168 169
 
169
-	containerID := strings.TrimSpace(out)
170
-
171
-	out, _ = dockerCmd(c, "wait", containerID)
170
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
172 171
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
173 172
 
174 173
 	assert.NilError(c, os.MkdirAll(cpTestPath, os.ModeDir))
... ...
@@ -186,9 +180,8 @@ func (s *DockerCLICpSuite) TestCpAbsoluteSymlink(c *testing.T) {
186 186
 	tmpname := filepath.Join(tmpdir, "container_path")
187 187
 	defer os.RemoveAll(tmpdir)
188 188
 
189
-	path := path.Join("/", "container_path")
190
-
191
-	dockerCmd(c, "cp", containerID+":"+path, tmpdir)
189
+	containerPath := path.Join("/", "container_path")
190
+	cli.DockerCmd(c, "cp", containerID+":"+containerPath, tmpdir)
192 191
 
193 192
 	// We should have copied a symlink *NOT* the file itself!
194 193
 	linkTarget, err := os.Readlink(tmpname)
... ...
@@ -200,11 +193,10 @@ func (s *DockerCLICpSuite) TestCpAbsoluteSymlink(c *testing.T) {
200 200
 // a container.
201 201
 func (s *DockerCLICpSuite) TestCpFromSymlinkToDirectory(c *testing.T) {
202 202
 	testRequires(c, DaemonIsLinux)
203
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPathParent+" /dir_link")
204
-
205
-	containerID := strings.TrimSpace(out)
203
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPathParent+" /dir_link").Stdout()
204
+	containerID = strings.TrimSpace(containerID)
206 205
 
207
-	out, _ = dockerCmd(c, "wait", containerID)
206
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
208 207
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
209 208
 
210 209
 	testDir, err := os.MkdirTemp("", "test-cp-from-symlink-to-dir-")
... ...
@@ -213,7 +205,7 @@ func (s *DockerCLICpSuite) TestCpFromSymlinkToDirectory(c *testing.T) {
213 213
 
214 214
 	// This copy command should copy the symlink, not the target, into the
215 215
 	// temporary directory.
216
-	dockerCmd(c, "cp", containerID+":"+"/dir_link", testDir)
216
+	cli.DockerCmd(c, "cp", containerID+":"+"/dir_link", testDir)
217 217
 
218 218
 	expectedPath := filepath.Join(testDir, "dir_link")
219 219
 	linkTarget, err := os.Readlink(expectedPath)
... ...
@@ -225,7 +217,7 @@ func (s *DockerCLICpSuite) TestCpFromSymlinkToDirectory(c *testing.T) {
225 225
 
226 226
 	// This copy command should resolve the symlink (note the trailing
227 227
 	// separator), copying the target into the temporary directory.
228
-	dockerCmd(c, "cp", containerID+":"+"/dir_link/", testDir)
228
+	cli.DockerCmd(c, "cp", containerID+":"+"/dir_link/", testDir)
229 229
 
230 230
 	// It *should not* have copied the directory using the target's name, but
231 231
 	// used the given name instead.
... ...
@@ -254,9 +246,8 @@ func (s *DockerCLICpSuite) TestCpToSymlinkToDirectory(c *testing.T) {
254 254
 
255 255
 	// Create a test container with a local volume. We will test by copying
256 256
 	// to the volume path in the container which we can then verify locally.
257
-	out, _ := dockerCmd(c, "create", "-v", testVol+":/testVol", "busybox")
258
-
259
-	containerID := strings.TrimSpace(out)
257
+	containerID := cli.DockerCmd(c, "create", "-v", testVol+":/testVol", "busybox").Stdout()
258
+	containerID = strings.TrimSpace(containerID)
260 259
 
261 260
 	// Create a temp directory to hold a test file nested in a directory.
262 261
 	testDir, err := os.MkdirTemp("", "test-cp-to-symlink-to-dir-")
... ...
@@ -281,7 +272,7 @@ func (s *DockerCLICpSuite) TestCpToSymlinkToDirectory(c *testing.T) {
281 281
 	assert.NilError(c, os.Symlink(linkTarget, localLink))
282 282
 
283 283
 	// Now copy that symlink into the test volume in the container.
284
-	dockerCmd(c, "cp", localLink, containerID+":/testVol")
284
+	cli.DockerCmd(c, "cp", localLink, containerID+":/testVol")
285 285
 
286 286
 	// This copy command should have copied the symlink *not* the target.
287 287
 	expectedPath := filepath.Join(testVol, "dir_link")
... ...
@@ -295,16 +286,15 @@ func (s *DockerCLICpSuite) TestCpToSymlinkToDirectory(c *testing.T) {
295 295
 	// This copy command should resolve the symlink (note the trailing
296 296
 	// separator), copying the target into the test volume directory in the
297 297
 	// container.
298
-	dockerCmd(c, "cp", localLink+"/", containerID+":/testVol")
298
+	cli.DockerCmd(c, "cp", localLink+"/", containerID+":/testVol")
299 299
 
300 300
 	// It *should not* have copied the directory using the target's name, but
301 301
 	// used the given name instead.
302 302
 	unexpectedPath := filepath.Join(testVol, cpTestPathParent)
303 303
 	stat, err := os.Lstat(unexpectedPath)
304 304
 	if err == nil {
305
-		out = fmt.Sprintf("target name was copied: %q - %q", stat.Mode(), stat.Name())
305
+		c.Errorf("target name was unexpectedly preserved: %q - %q", stat.Mode(), stat.Name())
306 306
 	}
307
-	assert.ErrorContains(c, err, "", out)
308 307
 
309 308
 	// It *should* have copied the directory using the asked name "dir_link".
310 309
 	stat, err = os.Lstat(expectedPath)
... ...
@@ -323,11 +313,10 @@ func (s *DockerCLICpSuite) TestCpToSymlinkToDirectory(c *testing.T) {
323 323
 // Check that symlinks which are part of the resource path are still relative to the container's rootfs
324 324
 func (s *DockerCLICpSuite) TestCpSymlinkComponent(c *testing.T) {
325 325
 	testRequires(c, DaemonIsLinux)
326
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path")
327
-
328
-	containerID := strings.TrimSpace(out)
326
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path").Stdout()
327
+	containerID = strings.TrimSpace(containerID)
329 328
 
330
-	out, _ = dockerCmd(c, "wait", containerID)
329
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
331 330
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
332 331
 
333 332
 	assert.NilError(c, os.MkdirAll(cpTestPath, os.ModeDir))
... ...
@@ -346,9 +335,8 @@ func (s *DockerCLICpSuite) TestCpSymlinkComponent(c *testing.T) {
346 346
 	tmpname := filepath.Join(tmpdir, cpTestName)
347 347
 	defer os.RemoveAll(tmpdir)
348 348
 
349
-	path := path.Join("/", "container_path", cpTestName)
350
-
351
-	dockerCmd(c, "cp", containerID+":"+path, tmpdir)
349
+	containerPath := path.Join("/", "container_path", cpTestName)
350
+	cli.DockerCmd(c, "cp", containerID+":"+containerPath, tmpdir)
352 351
 
353 352
 	file, _ := os.Open(tmpname)
354 353
 	defer file.Close()
... ...
@@ -364,11 +352,10 @@ func (s *DockerCLICpSuite) TestCpUnprivilegedUser(c *testing.T) {
364 364
 	testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
365 365
 	testRequires(c, UnixCli) // uses chmod/su: not available on windows
366 366
 
367
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
367
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName).Stdout()
368
+	containerID = strings.TrimSpace(containerID)
368 369
 
369
-	containerID := strings.TrimSpace(out)
370
-
371
-	out, _ = dockerCmd(c, "wait", containerID)
370
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
372 371
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
373 372
 
374 373
 	tmpdir, err := os.MkdirTemp("", "docker-integration")
... ...
@@ -379,8 +366,7 @@ func (s *DockerCLICpSuite) TestCpUnprivilegedUser(c *testing.T) {
379 379
 	err = os.Chmod(tmpdir, 0o777)
380 380
 	assert.NilError(c, err)
381 381
 
382
-	result := icmd.RunCommand("su", "unprivilegeduser", "-c",
383
-		fmt.Sprintf("%s cp %s:%s %s", dockerBinary, containerID, cpTestName, tmpdir))
382
+	result := icmd.RunCommand("su", "unprivilegeduser", "-c", fmt.Sprintf("%s cp %s:%s %s", dockerBinary, containerID, cpTestName, tmpdir))
384 383
 	result.Assert(c, icmd.Expected{})
385 384
 }
386 385
 
... ...
@@ -392,15 +378,14 @@ func (s *DockerCLICpSuite) TestCpSpecialFiles(c *testing.T) {
392 392
 	assert.NilError(c, err)
393 393
 	defer os.RemoveAll(outDir)
394 394
 
395
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo")
396
-
397
-	containerID := strings.TrimSpace(out)
395
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo").Stdout()
396
+	containerID = strings.TrimSpace(containerID)
398 397
 
399
-	out, _ = dockerCmd(c, "wait", containerID)
398
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
400 399
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
401 400
 
402 401
 	// Copy actual /etc/resolv.conf
403
-	dockerCmd(c, "cp", containerID+":/etc/resolv.conf", outDir)
402
+	cli.DockerCmd(c, "cp", containerID+":/etc/resolv.conf", outDir)
404 403
 
405 404
 	expected := readContainerFile(c, containerID, "resolv.conf")
406 405
 	actual, err := os.ReadFile(outDir + "/resolv.conf")
... ...
@@ -408,7 +393,7 @@ func (s *DockerCLICpSuite) TestCpSpecialFiles(c *testing.T) {
408 408
 	assert.Assert(c, bytes.Equal(actual, expected), "Expected copied file to be duplicate of the container resolvconf")
409 409
 
410 410
 	// Copy actual /etc/hosts
411
-	dockerCmd(c, "cp", containerID+":/etc/hosts", outDir)
411
+	cli.DockerCmd(c, "cp", containerID+":/etc/hosts", outDir)
412 412
 
413 413
 	expected = readContainerFile(c, containerID, "hosts")
414 414
 	actual, err = os.ReadFile(outDir + "/hosts")
... ...
@@ -416,7 +401,7 @@ func (s *DockerCLICpSuite) TestCpSpecialFiles(c *testing.T) {
416 416
 	assert.Assert(c, bytes.Equal(actual, expected), "Expected copied file to be duplicate of the container hosts")
417 417
 
418 418
 	// Copy actual /etc/resolv.conf
419
-	dockerCmd(c, "cp", containerID+":/etc/hostname", outDir)
419
+	cli.DockerCmd(c, "cp", containerID+":/etc/hostname", outDir)
420 420
 
421 421
 	expected = readContainerFile(c, containerID, "hostname")
422 422
 	actual, err = os.ReadFile(outDir + "/hostname")
... ...
@@ -439,15 +424,14 @@ func (s *DockerCLICpSuite) TestCpVolumePath(c *testing.T) {
439 439
 	_, err = os.Create(tmpDir + "/test")
440 440
 	assert.NilError(c, err)
441 441
 
442
-	out, _ := dockerCmd(c, "run", "-d", "-v", "/foo", "-v", tmpDir+"/test:/test", "-v", tmpDir+":/baz", "busybox", "/bin/sh", "-c", "touch /foo/bar")
442
+	containerID := cli.DockerCmd(c, "run", "-d", "-v", "/foo", "-v", tmpDir+"/test:/test", "-v", tmpDir+":/baz", "busybox", "/bin/sh", "-c", "touch /foo/bar").Stdout()
443
+	containerID = strings.TrimSpace(containerID)
443 444
 
444
-	containerID := strings.TrimSpace(out)
445
-
446
-	out, _ = dockerCmd(c, "wait", containerID)
445
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
447 446
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
448 447
 
449 448
 	// Copy actual volume path
450
-	dockerCmd(c, "cp", containerID+":/foo", outDir)
449
+	cli.DockerCmd(c, "cp", containerID+":/foo", outDir)
451 450
 
452 451
 	stat, err := os.Stat(outDir + "/foo")
453 452
 	assert.NilError(c, err)
... ...
@@ -458,20 +442,20 @@ func (s *DockerCLICpSuite) TestCpVolumePath(c *testing.T) {
458 458
 	assert.Assert(c, !stat.IsDir(), "Expected file `bar` to be a file")
459 459
 
460 460
 	// Copy file nested in volume
461
-	dockerCmd(c, "cp", containerID+":/foo/bar", outDir)
461
+	cli.DockerCmd(c, "cp", containerID+":/foo/bar", outDir)
462 462
 
463 463
 	stat, err = os.Stat(outDir + "/bar")
464 464
 	assert.NilError(c, err)
465 465
 	assert.Assert(c, !stat.IsDir(), "Expected file `bar` to be a file")
466 466
 
467 467
 	// Copy Bind-mounted dir
468
-	dockerCmd(c, "cp", containerID+":/baz", outDir)
468
+	cli.DockerCmd(c, "cp", containerID+":/baz", outDir)
469 469
 	stat, err = os.Stat(outDir + "/baz")
470 470
 	assert.NilError(c, err)
471 471
 	assert.Assert(c, stat.IsDir(), "Expected `baz` to be a dir")
472 472
 
473 473
 	// Copy file nested in bind-mounted dir
474
-	dockerCmd(c, "cp", containerID+":/baz/test", outDir)
474
+	cli.DockerCmd(c, "cp", containerID+":/baz/test", outDir)
475 475
 	fb, err := os.ReadFile(outDir + "/baz/test")
476 476
 	assert.NilError(c, err)
477 477
 	fb2, err := os.ReadFile(tmpDir + "/test")
... ...
@@ -479,7 +463,7 @@ func (s *DockerCLICpSuite) TestCpVolumePath(c *testing.T) {
479 479
 	assert.Assert(c, bytes.Equal(fb, fb2), "Expected copied file to be duplicate of bind-mounted file")
480 480
 
481 481
 	// Copy bind-mounted file
482
-	dockerCmd(c, "cp", containerID+":/test", outDir)
482
+	cli.DockerCmd(c, "cp", containerID+":/test", outDir)
483 483
 	fb, err = os.ReadFile(outDir + "/test")
484 484
 	assert.NilError(c, err)
485 485
 	fb2, err = os.ReadFile(tmpDir + "/test")
... ...
@@ -488,11 +472,10 @@ func (s *DockerCLICpSuite) TestCpVolumePath(c *testing.T) {
488 488
 }
489 489
 
490 490
 func (s *DockerCLICpSuite) TestCpToDot(c *testing.T) {
491
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
492
-
493
-	containerID := strings.TrimSpace(out)
491
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test").Stdout()
492
+	containerID = strings.TrimSpace(containerID)
494 493
 
495
-	out, _ = dockerCmd(c, "wait", containerID)
494
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
496 495
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
497 496
 
498 497
 	tmpdir, err := os.MkdirTemp("", "docker-integration")
... ...
@@ -504,18 +487,17 @@ func (s *DockerCLICpSuite) TestCpToDot(c *testing.T) {
504 504
 	err = os.Chdir(tmpdir)
505 505
 	assert.NilError(c, err)
506 506
 
507
-	dockerCmd(c, "cp", containerID+":/test", ".")
507
+	cli.DockerCmd(c, "cp", containerID+":/test", ".")
508 508
 	content, err := os.ReadFile("./test")
509 509
 	assert.NilError(c, err)
510 510
 	assert.Equal(c, string(content), "lololol\n")
511 511
 }
512 512
 
513 513
 func (s *DockerCLICpSuite) TestCpToStdout(c *testing.T) {
514
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
515
-
516
-	containerID := strings.TrimSpace(out)
514
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test").Stdout()
515
+	containerID = strings.TrimSpace(containerID)
517 516
 
518
-	out, _ = dockerCmd(c, "wait", containerID)
517
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
519 518
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
520 519
 
521 520
 	out, err := RunCommandPipelineWithOutput(
... ...
@@ -530,17 +512,16 @@ func (s *DockerCLICpSuite) TestCpToStdout(c *testing.T) {
530 530
 func (s *DockerCLICpSuite) TestCpNameHasColon(c *testing.T) {
531 531
 	testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
532 532
 
533
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t")
533
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t").Stdout()
534
+	containerID = strings.TrimSpace(containerID)
534 535
 
535
-	containerID := strings.TrimSpace(out)
536
-
537
-	out, _ = dockerCmd(c, "wait", containerID)
536
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
538 537
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
539 538
 
540 539
 	tmpdir, err := os.MkdirTemp("", "docker-integration")
541 540
 	assert.NilError(c, err)
542 541
 	defer os.RemoveAll(tmpdir)
543
-	dockerCmd(c, "cp", containerID+":/te:s:t", tmpdir)
542
+	cli.DockerCmd(c, "cp", containerID+":/te:s:t", tmpdir)
544 543
 	content, err := os.ReadFile(tmpdir + "/te:s:t")
545 544
 	assert.NilError(c, err)
546 545
 	assert.Equal(c, string(content), "lololol\n")
... ...
@@ -548,31 +529,31 @@ func (s *DockerCLICpSuite) TestCpNameHasColon(c *testing.T) {
548 548
 
549 549
 func (s *DockerCLICpSuite) TestCopyAndRestart(c *testing.T) {
550 550
 	testRequires(c, DaemonIsLinux)
551
-	expectedMsg := "hello"
552
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg)
553
-	containerID := strings.TrimSpace(out)
551
+	const expectedMsg = "hello"
552
+	containerID := cli.DockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg).Stdout()
553
+	containerID = strings.TrimSpace(containerID)
554 554
 
555
-	out, _ = dockerCmd(c, "wait", containerID)
555
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
556 556
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
557 557
 
558 558
 	tmpDir, err := os.MkdirTemp("", "test-docker-restart-after-copy-")
559 559
 	assert.NilError(c, err)
560 560
 	defer os.RemoveAll(tmpDir)
561 561
 
562
-	dockerCmd(c, "cp", fmt.Sprintf("%s:/etc/group", containerID), tmpDir)
562
+	cli.DockerCmd(c, "cp", fmt.Sprintf("%s:/etc/group", containerID), tmpDir)
563 563
 
564
-	out, _ = dockerCmd(c, "start", "-a", containerID)
564
+	out = cli.DockerCmd(c, "start", "-a", containerID).Combined()
565 565
 	assert.Equal(c, strings.TrimSpace(out), expectedMsg)
566 566
 }
567 567
 
568 568
 func (s *DockerCLICpSuite) TestCopyCreatedContainer(c *testing.T) {
569 569
 	testRequires(c, DaemonIsLinux)
570
-	dockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox")
570
+	cli.DockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox")
571 571
 
572 572
 	tmpDir, err := os.MkdirTemp("", "test")
573 573
 	assert.NilError(c, err)
574 574
 	defer os.RemoveAll(tmpDir)
575
-	dockerCmd(c, "cp", "test_cp:/bin/sh", tmpDir)
575
+	cli.DockerCmd(c, "cp", "test_cp:/bin/sh", tmpDir)
576 576
 }
577 577
 
578 578
 // test copy with option `-L`: following symbol link
... ...
@@ -580,12 +561,11 @@ func (s *DockerCLICpSuite) TestCopyCreatedContainer(c *testing.T) {
580 580
 // a container to host following symbol link
581 581
 func (s *DockerCLICpSuite) TestCpSymlinkFromConToHostFollowSymlink(c *testing.T) {
582 582
 	testRequires(c, DaemonIsLinux)
583
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" /dir_link")
584
-	assert.Equal(c, exitCode, 0, "failed to set up container: %s", out)
585
-
586
-	cleanedContainerID := strings.TrimSpace(out)
583
+	result := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" /dir_link")
584
+	assert.Equal(c, result.ExitCode, 0, "failed to set up container: %s", result.Combined())
585
+	containerID := strings.TrimSpace(result.Stdout())
587 586
 
588
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
587
+	out := cli.DockerCmd(c, "wait", containerID).Combined()
589 588
 	assert.Equal(c, strings.TrimSpace(out), "0", "failed to set up container")
590 589
 
591 590
 	testDir, err := os.MkdirTemp("", "test-cp-symlink-container-to-host-follow-symlink")
... ...
@@ -594,7 +574,7 @@ func (s *DockerCLICpSuite) TestCpSymlinkFromConToHostFollowSymlink(c *testing.T)
594 594
 
595 595
 	// This copy command should copy the symlink, not the target, into the
596 596
 	// temporary directory.
597
-	dockerCmd(c, "cp", "-L", cleanedContainerID+":"+"/dir_link", testDir)
597
+	cli.DockerCmd(c, "cp", "-L", containerID+":"+"/dir_link", testDir)
598 598
 
599 599
 	expectedPath := filepath.Join(testDir, "dir_link")
600 600
 
... ...
@@ -611,7 +591,7 @@ func (s *DockerCLICpSuite) TestCpSymlinkFromConToHostFollowSymlink(c *testing.T)
611 611
 		os.Remove(expectedPath)
612 612
 	}
613 613
 
614
-	dockerCmd(c, "cp", "-L", cleanedContainerID+":"+"/dir_link", expectedPath)
614
+	cli.DockerCmd(c, "cp", "-L", containerID+":"+"/dir_link", expectedPath)
615 615
 
616 616
 	actual, err = os.ReadFile(expectedPath)
617 617
 	assert.NilError(c, err)
... ...
@@ -12,6 +12,7 @@ import (
12 12
 	"syscall"
13 13
 	"testing"
14 14
 
15
+	"github.com/docker/docker/integration-cli/cli"
15 16
 	"gotest.tools/v3/assert"
16 17
 )
17 18
 
... ...
@@ -25,9 +26,9 @@ func (s *DockerCLICpSuite) TestCpToContainerWithPermissions(c *testing.T) {
25 25
 
26 26
 	containerName := "permtest"
27 27
 
28
-	_, exc := dockerCmd(c, "create", "--name", containerName, "busybox", "/bin/sh", "-c", "stat -c '%u %g %a' /permdirtest /permdirtest/permtest")
28
+	exc := cli.DockerCmd(c, "create", "--name", containerName, "busybox", "/bin/sh", "-c", "stat -c '%u %g %a' /permdirtest /permdirtest/permtest").ExitCode
29 29
 	assert.Equal(c, exc, 0)
30
-	defer dockerCmd(c, "rm", "-f", containerName)
30
+	defer cli.DockerCmd(c, "rm", "-f", containerName)
31 31
 
32 32
 	srcPath := cpPath(tmpDir, "permdirtest")
33 33
 	dstPath := containerCpPath(containerName, "/")
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"strings"
12 12
 	"testing"
13 13
 
14
+	"github.com/docker/docker/integration-cli/cli"
14 15
 	"github.com/docker/docker/pkg/archive"
15 16
 	"gotest.tools/v3/assert"
16 17
 )
... ...
@@ -150,15 +151,15 @@ func makeTestContainer(c *testing.T, options testContainerOptions) (containerID
150 150
 
151 151
 	args = append(args, "busybox", "/bin/sh", "-c", options.command)
152 152
 
153
-	out, _ := dockerCmd(c, args...)
153
+	out := cli.DockerCmd(c, args...).Combined()
154 154
 
155 155
 	containerID = strings.TrimSpace(out)
156 156
 
157
-	out, _ = dockerCmd(c, "wait", containerID)
157
+	out = cli.DockerCmd(c, "wait", containerID).Combined()
158 158
 
159 159
 	exitCode := strings.TrimSpace(out)
160 160
 	if exitCode != "0" {
161
-		out, _ = dockerCmd(c, "logs", containerID)
161
+		out = cli.DockerCmd(c, "logs", containerID).Combined()
162 162
 	}
163 163
 	assert.Equal(c, exitCode, "0", "failed to make test container: %s", out)
164 164