Browse code

integration-cli: DockerRegistrySuite: replace dockerCmd

Also renaming vars that collided with package-level vars
and using consts for fixed values.

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

Sebastiaan van Stijn authored on 2023/07/28 03:01:09
Showing 5 changed files
... ...
@@ -20,9 +20,12 @@ import (
20 20
 	"gotest.tools/v3/skip"
21 21
 )
22 22
 
23
+const (
24
+	remoteRepoName = "dockercli/busybox-by-dgst"
25
+	repoName       = privateRegistryURL + "/" + remoteRepoName
26
+)
27
+
23 28
 var (
24
-	remoteRepoName  = "dockercli/busybox-by-dgst"
25
-	repoName        = fmt.Sprintf("%s/%s", privateRegistryURL, remoteRepoName)
26 29
 	pushDigestRegex = regexp.MustCompile(`[\S]+: digest: ([\S]+) size: [0-9]+`)
27 30
 	digestRegex     = regexp.MustCompile(`Digest: ([\S]+)`)
28 31
 )
... ...
@@ -32,7 +35,7 @@ func setupImage(c *testing.T) (digest.Digest, error) {
32 32
 }
33 33
 
34 34
 func setupImageWithTag(c *testing.T, tag string) (digest.Digest, error) {
35
-	containerName := "busyboxbydigest"
35
+	const containerName = "busyboxbydigest"
36 36
 
37 37
 	// new file is committed because this layer is used for detecting malicious
38 38
 	// changes. if this was committed as empty layer it would be skipped on pull
... ...
@@ -65,7 +68,7 @@ func testPullByTagDisplaysDigest(c *testing.T) {
65 65
 	assert.NilError(c, err, "error setting up image")
66 66
 
67 67
 	// pull from the registry using the tag
68
-	out, _ := dockerCmd(c, "pull", repoName)
68
+	out := cli.DockerCmd(c, "pull", repoName).Combined()
69 69
 
70 70
 	// the pull output includes "Digest: <digest>", so find that
71 71
 	matches := digestRegex.FindStringSubmatch(out)
... ...
@@ -91,7 +94,7 @@ func testPullByDigest(c *testing.T) {
91 91
 
92 92
 	// pull from the registry using the <name>@<digest> reference
93 93
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
94
-	out, _ := dockerCmd(c, "pull", imageReference)
94
+	out := cli.DockerCmd(c, "pull", imageReference).Combined()
95 95
 
96 96
 	// the pull output includes "Digest: <digest>", so find that
97 97
 	matches := digestRegex.FindStringSubmatch(out)
... ...
@@ -139,8 +142,8 @@ func (s *DockerRegistrySuite) TestCreateByDigest(c *testing.T) {
139 139
 
140 140
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
141 141
 
142
-	containerName := "createByDigest"
143
-	dockerCmd(c, "create", "--name", containerName, imageReference)
142
+	const containerName = "createByDigest"
143
+	cli.DockerCmd(c, "create", "--name", containerName, imageReference)
144 144
 
145 145
 	res := inspectField(c, containerName, "Config.Image")
146 146
 	assert.Equal(c, res, imageReference)
... ...
@@ -152,8 +155,8 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *testing.T) {
152 152
 
153 153
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
154 154
 
155
-	containerName := "runByDigest"
156
-	out, _ := dockerCmd(c, "run", "--name", containerName, imageReference, "sh", "-c", "echo found=$digest")
155
+	const containerName = "runByDigest"
156
+	out := cli.DockerCmd(c, "run", "--name", containerName, imageReference, "sh", "-c", "echo found=$digest").Combined()
157 157
 
158 158
 	foundRegex := regexp.MustCompile("found=([^\n]+)")
159 159
 	matches := foundRegex.FindStringSubmatch(out)
... ...
@@ -165,13 +168,13 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *testing.T) {
165 165
 }
166 166
 
167 167
 func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *testing.T) {
168
-	digest, err := setupImage(c)
168
+	imgDigest, err := setupImage(c)
169 169
 	assert.NilError(c, err, "error setting up image")
170 170
 
171
-	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
171
+	imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest)
172 172
 
173 173
 	// pull from the registry using the <name>@<digest> reference
174
-	dockerCmd(c, "pull", imageReference)
174
+	cli.DockerCmd(c, "pull", imageReference)
175 175
 
176 176
 	// make sure inspect runs ok
177 177
 	inspectField(c, imageReference, "Id")
... ...
@@ -188,19 +191,19 @@ func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *testing.T) {
188 188
 
189 189
 func (s *DockerRegistrySuite) TestBuildByDigest(c *testing.T) {
190 190
 	skip.If(c, testEnv.UsingSnapshotter(), "Config.Image is not created with containerd, buildkit doesn't set it either")
191
-	digest, err := setupImage(c)
191
+	imgDigest, err := setupImage(c)
192 192
 	assert.NilError(c, err, "error setting up image")
193 193
 
194
-	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
194
+	imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest)
195 195
 
196 196
 	// pull from the registry using the <name>@<digest> reference
197
-	dockerCmd(c, "pull", imageReference)
197
+	cli.DockerCmd(c, "pull", imageReference)
198 198
 
199 199
 	// get the image id
200 200
 	imageID := inspectField(c, imageReference, "Id")
201 201
 
202 202
 	// do the build
203
-	name := "buildbydigest"
203
+	const name = "buildbydigest"
204 204
 	buildImageSuccessfully(c, name, build.WithDockerfile(fmt.Sprintf(
205 205
 		`FROM %s
206 206
      CMD ["/bin/echo", "Hello World"]`, imageReference)))
... ...
@@ -213,17 +216,17 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *testing.T) {
213 213
 }
214 214
 
215 215
 func (s *DockerRegistrySuite) TestTagByDigest(c *testing.T) {
216
-	digest, err := setupImage(c)
216
+	imgDigest, err := setupImage(c)
217 217
 	assert.NilError(c, err, "error setting up image")
218 218
 
219
-	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
219
+	imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest)
220 220
 
221 221
 	// pull from the registry using the <name>@<digest> reference
222
-	dockerCmd(c, "pull", imageReference)
222
+	cli.DockerCmd(c, "pull", imageReference)
223 223
 
224 224
 	// tag it
225
-	tag := "tagbydigest"
226
-	dockerCmd(c, "tag", imageReference, tag)
225
+	const tag = "tagbydigest"
226
+	cli.DockerCmd(c, "tag", imageReference, tag)
227 227
 
228 228
 	expectedID := inspectField(c, imageReference, "Id")
229 229
 
... ...
@@ -232,15 +235,15 @@ func (s *DockerRegistrySuite) TestTagByDigest(c *testing.T) {
232 232
 }
233 233
 
234 234
 func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *testing.T) {
235
-	digest, err := setupImage(c)
235
+	imgDigest, err := setupImage(c)
236 236
 	assert.NilError(c, err, "error setting up image")
237 237
 
238
-	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
238
+	imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest)
239 239
 
240 240
 	// pull from the registry using the <name>@<digest> reference
241
-	dockerCmd(c, "pull", imageReference)
241
+	cli.DockerCmd(c, "pull", imageReference)
242 242
 
243
-	out, _ := dockerCmd(c, "images")
243
+	out := cli.DockerCmd(c, "images").Stdout()
244 244
 	assert.Assert(c, !strings.Contains(out, "DIGEST"), "list output should not have contained DIGEST header")
245 245
 }
246 246
 
... ...
@@ -252,10 +255,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
252 252
 	c.Logf("imageReference1 = %s", imageReference1)
253 253
 
254 254
 	// pull image1 by digest
255
-	dockerCmd(c, "pull", imageReference1)
255
+	cli.DockerCmd(c, "pull", imageReference1)
256 256
 
257 257
 	// list images
258
-	out, _ := dockerCmd(c, "images", "--digests")
258
+	out := cli.DockerCmd(c, "images", "--digests").Combined()
259 259
 
260 260
 	// make sure repo shown, tag=<none>, digest = $digest1
261 261
 	re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`)
... ...
@@ -267,13 +270,13 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
267 267
 	c.Logf("imageReference2 = %s", imageReference2)
268 268
 
269 269
 	// pull image1 by digest
270
-	dockerCmd(c, "pull", imageReference1)
270
+	cli.DockerCmd(c, "pull", imageReference1)
271 271
 
272 272
 	// pull image2 by digest
273
-	dockerCmd(c, "pull", imageReference2)
273
+	cli.DockerCmd(c, "pull", imageReference2)
274 274
 
275 275
 	// list images
276
-	out, _ = dockerCmd(c, "images", "--digests")
276
+	out = cli.DockerCmd(c, "images", "--digests").Stdout()
277 277
 
278 278
 	// make sure repo shown, tag=<none>, digest = $digest1
279 279
 	assert.Assert(c, re1.MatchString(out), "expected %q: %s", re1.String(), out)
... ...
@@ -283,10 +286,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
283 283
 	assert.Assert(c, re2.MatchString(out), "expected %q: %s", re2.String(), out)
284 284
 
285 285
 	// pull tag1
286
-	dockerCmd(c, "pull", repoName+":tag1")
286
+	cli.DockerCmd(c, "pull", repoName+":tag1")
287 287
 
288 288
 	// list images
289
-	out, _ = dockerCmd(c, "images", "--digests")
289
+	out = cli.DockerCmd(c, "images", "--digests").Stdout()
290 290
 
291 291
 	// make sure image 1 has repo, tag, <none> AND repo, <none>, digest
292 292
 	reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*` + digest1.String() + `\s`)
... ...
@@ -295,10 +298,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
295 295
 	assert.Assert(c, re2.MatchString(out), "expected %q: %s", re2.String(), out)
296 296
 
297 297
 	// pull tag 2
298
-	dockerCmd(c, "pull", repoName+":tag2")
298
+	cli.DockerCmd(c, "pull", repoName+":tag2")
299 299
 
300 300
 	// list images
301
-	out, _ = dockerCmd(c, "images", "--digests")
301
+	out = cli.DockerCmd(c, "images", "--digests").Stdout()
302 302
 
303 303
 	// make sure image 1 has repo, tag, digest
304 304
 	assert.Assert(c, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out)
... ...
@@ -308,7 +311,7 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
308 308
 	assert.Assert(c, reWithDigest2.MatchString(out), "expected %q: %s", reWithDigest2.String(), out)
309 309
 
310 310
 	// list images
311
-	out, _ = dockerCmd(c, "images", "--digests")
311
+	out = cli.DockerCmd(c, "images", "--digests").Stdout()
312 312
 
313 313
 	// make sure image 1 has repo, tag, digest
314 314
 	assert.Assert(c, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out)
... ...
@@ -327,10 +330,10 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
327 327
 	c.Logf("imageReference1 = %s", imageReference1)
328 328
 
329 329
 	// pull image1 by digest
330
-	dockerCmd(c, "pull", imageReference1)
330
+	cli.DockerCmd(c, "pull", imageReference1)
331 331
 
332 332
 	// list images
333
-	out, _ := dockerCmd(c, "images", "--digests")
333
+	out := cli.DockerCmd(c, "images", "--digests").Stdout()
334 334
 
335 335
 	// make sure repo shown, tag=<none>, digest = $digest1
336 336
 	re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`)
... ...
@@ -343,13 +346,13 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
343 343
 	c.Logf("imageReference2 = %s", imageReference2)
344 344
 
345 345
 	// pull image1 by digest
346
-	dockerCmd(c, "pull", imageReference1)
346
+	cli.DockerCmd(c, "pull", imageReference1)
347 347
 
348 348
 	// pull image2 by digest
349
-	dockerCmd(c, "pull", imageReference2)
349
+	cli.DockerCmd(c, "pull", imageReference2)
350 350
 
351 351
 	// list images
352
-	out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true")
352
+	out = cli.DockerCmd(c, "images", "--digests", "--filter=dangling=true").Stdout()
353 353
 
354 354
 	// make sure repo shown, tag=<none>, digest = $digest1
355 355
 	assert.Assert(c, re1.MatchString(out), "expected %q: %s", re1.String(), out)
... ...
@@ -359,10 +362,10 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
359 359
 	assert.Assert(c, re2.MatchString(out), "expected %q: %s", re2.String(), out)
360 360
 
361 361
 	// pull dangle1 tag
362
-	dockerCmd(c, "pull", repoName+":dangle1")
362
+	cli.DockerCmd(c, "pull", repoName+":dangle1")
363 363
 
364 364
 	// list images
365
-	out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true")
365
+	out = cli.DockerCmd(c, "images", "--digests", "--filter=dangling=true").Stdout()
366 366
 
367 367
 	// make sure image 1 has repo, tag, <none> AND repo, <none>, digest
368 368
 	reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*dangle1\s*` + digest1.String() + `\s`)
... ...
@@ -371,10 +374,10 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
371 371
 	assert.Assert(c, re2.MatchString(out), "expected %q: %s", re2.String(), out)
372 372
 
373 373
 	// pull dangle2 tag
374
-	dockerCmd(c, "pull", repoName+":dangle2")
374
+	cli.DockerCmd(c, "pull", repoName+":dangle2")
375 375
 
376 376
 	// list images, show tagged images
377
-	out, _ = dockerCmd(c, "images", "--digests")
377
+	out = cli.DockerCmd(c, "images", "--digests").Stdout()
378 378
 
379 379
 	// make sure image 1 has repo, tag, digest
380 380
 	assert.Assert(c, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out)
... ...
@@ -384,7 +387,7 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
384 384
 	assert.Assert(c, reWithDigest2.MatchString(out), "expected %q: %s", reWithDigest2.String(), out)
385 385
 
386 386
 	// list images, no longer dangling, should not match
387
-	out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true")
387
+	out = cli.DockerCmd(c, "images", "--digests", "--filter=dangling=true").Stdout()
388 388
 
389 389
 	// make sure image 1 has repo, tag, digest
390 390
 	assert.Assert(c, !reWithDigest1.MatchString(out), "unexpected %q: %s", reWithDigest1.String(), out)
... ...
@@ -393,15 +396,15 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
393 393
 }
394 394
 
395 395
 func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *testing.T) {
396
-	digest, err := setupImage(c)
396
+	imgDigest, err := setupImage(c)
397 397
 	assert.Assert(c, err == nil, "error setting up image")
398 398
 
399
-	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
399
+	imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest)
400 400
 
401 401
 	// pull from the registry using the <name>@<digest> reference
402
-	dockerCmd(c, "pull", imageReference)
402
+	cli.DockerCmd(c, "pull", imageReference)
403 403
 
404
-	out, _ := dockerCmd(c, "inspect", imageReference)
404
+	out := cli.DockerCmd(c, "inspect", imageReference).Stdout()
405 405
 
406 406
 	var imageJSON []types.ImageInspect
407 407
 	err = json.Unmarshal([]byte(out), &imageJSON)
... ...
@@ -414,36 +417,36 @@ func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *testing.T) {
414 414
 func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c *testing.T) {
415 415
 	existingContainers := ExistingContainerIDs(c)
416 416
 
417
-	digest, err := setupImage(c)
417
+	imgDigest, err := setupImage(c)
418 418
 	assert.NilError(c, err, "error setting up image")
419 419
 
420
-	imageReference := fmt.Sprintf("%s@%s", repoName, digest)
420
+	imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest)
421 421
 
422 422
 	// pull from the registry using the <name>@<digest> reference
423
-	dockerCmd(c, "pull", imageReference)
423
+	cli.DockerCmd(c, "pull", imageReference)
424 424
 
425 425
 	// build an image from it
426
-	imageName1 := "images_ps_filter_test"
426
+	const imageName1 = "images_ps_filter_test"
427 427
 	buildImageSuccessfully(c, imageName1, build.WithDockerfile(fmt.Sprintf(
428 428
 		`FROM %s
429 429
 		 LABEL match me 1`, imageReference)))
430 430
 
431 431
 	// run a container based on that
432
-	dockerCmd(c, "run", "--name=test1", imageReference, "echo", "hello")
432
+	cli.DockerCmd(c, "run", "--name=test1", imageReference, "echo", "hello")
433 433
 	expectedID := getIDByName(c, "test1")
434 434
 
435 435
 	// run a container based on the a descendant of that too
436
-	dockerCmd(c, "run", "--name=test2", imageName1, "echo", "hello")
436
+	cli.DockerCmd(c, "run", "--name=test2", imageName1, "echo", "hello")
437 437
 	expectedID1 := getIDByName(c, "test2")
438 438
 
439 439
 	expectedIDs := []string{expectedID, expectedID1}
440 440
 
441 441
 	// Invalid imageReference
442
-	out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", fmt.Sprintf("--filter=ancestor=busybox@%s", digest))
442
+	out := cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc", fmt.Sprintf("--filter=ancestor=busybox@%s", imgDigest)).Stdout()
443 443
 	assert.Equal(c, strings.TrimSpace(out), "", "Filter container for ancestor filter should be empty")
444 444
 
445 445
 	// Valid imageReference
446
-	out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+imageReference)
446
+	out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+imageReference).Stdout()
447 447
 	checkPsAncestorFilterOutput(c, RemoveOutputForExistingElements(out, existingContainers), imageReference, expectedIDs)
448 448
 }
449 449
 
... ...
@@ -453,14 +456,14 @@ func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *testing.T
453 453
 
454 454
 	// pull from the registry using the <name>@<digest> reference
455 455
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
456
-	dockerCmd(c, "pull", imageReference)
456
+	cli.DockerCmd(c, "pull", imageReference)
457 457
 	// just in case...
458 458
 
459
-	dockerCmd(c, "tag", imageReference, repoName+":sometag")
459
+	cli.DockerCmd(c, "tag", imageReference, repoName+":sometag")
460 460
 
461 461
 	imageID := inspectField(c, imageReference, "Id")
462 462
 
463
-	dockerCmd(c, "rmi", imageID)
463
+	cli.DockerCmd(c, "rmi", imageID)
464 464
 
465 465
 	_, err = inspectFieldWithError(imageID, "Id")
466 466
 	assert.ErrorContains(c, err, "", "image should have been deleted")
... ...
@@ -472,21 +475,21 @@ func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndTag(c *testing.T) {
472 472
 
473 473
 	// pull from the registry using the <name>@<digest> reference
474 474
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
475
-	dockerCmd(c, "pull", imageReference)
475
+	cli.DockerCmd(c, "pull", imageReference)
476 476
 
477 477
 	imageID := inspectField(c, imageReference, "Id")
478 478
 
479
-	repoTag := repoName + ":sometag"
480
-	repoTag2 := repoName + ":othertag"
481
-	dockerCmd(c, "tag", imageReference, repoTag)
482
-	dockerCmd(c, "tag", imageReference, repoTag2)
479
+	const repoTag = repoName + ":sometag"
480
+	const repoTag2 = repoName + ":othertag"
481
+	cli.DockerCmd(c, "tag", imageReference, repoTag)
482
+	cli.DockerCmd(c, "tag", imageReference, repoTag2)
483 483
 
484
-	dockerCmd(c, "rmi", repoTag2)
484
+	cli.DockerCmd(c, "rmi", repoTag2)
485 485
 
486 486
 	// rmi should have deleted only repoTag2, because there's another tag
487 487
 	inspectField(c, repoTag, "Id")
488 488
 
489
-	dockerCmd(c, "rmi", repoTag)
489
+	cli.DockerCmd(c, "rmi", repoTag)
490 490
 
491 491
 	// rmi should have deleted the tag, the digest reference, and the image itself
492 492
 	_, err = inspectFieldWithError(imageID, "Id")
... ...
@@ -501,16 +504,16 @@ func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndMultiRepoTag(c *testin
501 501
 
502 502
 	// pull from the registry using the <name>@<digest> reference
503 503
 	imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
504
-	dockerCmd(c, "pull", imageReference)
504
+	cli.DockerCmd(c, "pull", imageReference)
505 505
 
506 506
 	imageID := inspectField(c, imageReference, "Id")
507 507
 
508 508
 	repoTag := repoName + ":sometag"
509 509
 	repoTag2 := repo2 + ":othertag"
510
-	dockerCmd(c, "tag", imageReference, repoTag)
511
-	dockerCmd(c, "tag", imageReference, repoTag2)
510
+	cli.DockerCmd(c, "tag", imageReference, repoTag)
511
+	cli.DockerCmd(c, "tag", imageReference, repoTag2)
512 512
 
513
-	dockerCmd(c, "rmi", repoTag)
513
+	cli.DockerCmd(c, "rmi", repoTag)
514 514
 
515 515
 	// rmi should have deleted repoTag and image reference, but left repoTag2
516 516
 	inspectField(c, repoTag2, "Id")
... ...
@@ -520,7 +523,7 @@ func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndMultiRepoTag(c *testin
520 520
 	_, err = inspectFieldWithError(repoTag, "Id")
521 521
 	assert.ErrorContains(c, err, "", "image tag reference should have been removed")
522 522
 
523
-	dockerCmd(c, "rmi", repoTag2)
523
+	cli.DockerCmd(c, "rmi", repoTag2)
524 524
 
525 525
 	// rmi should have deleted the tag, the digest reference, and the image itself
526 526
 	_, err = inspectFieldWithError(imageID, "Id")
... ...
@@ -13,6 +13,7 @@ import (
13 13
 	"github.com/docker/distribution/manifest"
14 14
 	"github.com/docker/distribution/manifest/manifestlist"
15 15
 	"github.com/docker/distribution/manifest/schema2"
16
+	"github.com/docker/docker/integration-cli/cli"
16 17
 	"github.com/docker/docker/integration-cli/cli/build"
17 18
 	"github.com/opencontainers/go-digest"
18 19
 	"gotest.tools/v3/assert"
... ...
@@ -24,26 +25,26 @@ import (
24 24
 //
25 25
 // Ref: docker/docker#8141
26 26
 func testPullImageWithAliases(c *testing.T) {
27
-	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
27
+	const imgRepo = privateRegistryURL + "/dockercli/busybox"
28 28
 
29 29
 	var repos []string
30 30
 	for _, tag := range []string{"recent", "fresh"} {
31
-		repos = append(repos, fmt.Sprintf("%v:%v", repoName, tag))
31
+		repos = append(repos, fmt.Sprintf("%v:%v", imgRepo, tag))
32 32
 	}
33 33
 
34 34
 	// Tag and push the same image multiple times.
35 35
 	for _, repo := range repos {
36
-		dockerCmd(c, "tag", "busybox", repo)
37
-		dockerCmd(c, "push", repo)
36
+		cli.DockerCmd(c, "tag", "busybox", repo)
37
+		cli.DockerCmd(c, "push", repo)
38 38
 	}
39 39
 
40 40
 	// Clear local images store.
41 41
 	args := append([]string{"rmi"}, repos...)
42
-	dockerCmd(c, args...)
42
+	cli.DockerCmd(c, args...)
43 43
 
44 44
 	// Pull a single tag and verify it doesn't bring down all aliases.
45
-	dockerCmd(c, "pull", repos[0])
46
-	dockerCmd(c, "inspect", repos[0])
45
+	cli.DockerCmd(c, "pull", repos[0])
46
+	cli.DockerCmd(c, "inspect", repos[0])
47 47
 	for _, repo := range repos[1:] {
48 48
 		_, _, err := dockerCmdWithError("inspect", repo)
49 49
 		assert.ErrorContains(c, err, "", "Image %v shouldn't have been pulled down", repo)
... ...
@@ -60,11 +61,11 @@ func (s *DockerSchema1RegistrySuite) TestPullImageWithAliases(c *testing.T) {
60 60
 
61 61
 // testConcurrentPullWholeRepo pulls the same repo concurrently.
62 62
 func testConcurrentPullWholeRepo(c *testing.T) {
63
-	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
63
+	const imgRepo = privateRegistryURL + "/dockercli/busybox"
64 64
 
65 65
 	var repos []string
66 66
 	for _, tag := range []string{"recent", "fresh", "todays"} {
67
-		repo := fmt.Sprintf("%v:%v", repoName, tag)
67
+		repo := fmt.Sprintf("%v:%v", imgRepo, tag)
68 68
 		buildImageSuccessfully(c, repo, build.WithDockerfile(fmt.Sprintf(`
69 69
 		    FROM busybox
70 70
 		    ENTRYPOINT ["/bin/echo"]
... ...
@@ -72,13 +73,13 @@ func testConcurrentPullWholeRepo(c *testing.T) {
72 72
 		    ENV BAR bar
73 73
 		    CMD echo %s
74 74
 		`, repo)))
75
-		dockerCmd(c, "push", repo)
75
+		cli.DockerCmd(c, "push", repo)
76 76
 		repos = append(repos, repo)
77 77
 	}
78 78
 
79 79
 	// Clear local images store.
80 80
 	args := append([]string{"rmi"}, repos...)
81
-	dockerCmd(c, args...)
81
+	cli.DockerCmd(c, args...)
82 82
 
83 83
 	// Run multiple re-pulls concurrently
84 84
 	numPulls := 3
... ...
@@ -86,7 +87,7 @@ func testConcurrentPullWholeRepo(c *testing.T) {
86 86
 
87 87
 	for i := 0; i != numPulls; i++ {
88 88
 		go func() {
89
-			result := icmd.RunCommand(dockerBinary, "pull", "-a", repoName)
89
+			result := icmd.RunCommand(dockerBinary, "pull", "-a", imgRepo)
90 90
 			results <- result.Error
91 91
 		}()
92 92
 	}
... ...
@@ -100,8 +101,8 @@ func testConcurrentPullWholeRepo(c *testing.T) {
100 100
 
101 101
 	// Ensure all tags were pulled successfully
102 102
 	for _, repo := range repos {
103
-		dockerCmd(c, "inspect", repo)
104
-		out, _ := dockerCmd(c, "run", "--rm", repo)
103
+		cli.DockerCmd(c, "inspect", repo)
104
+		out := cli.DockerCmd(c, "run", "--rm", repo).Combined()
105 105
 		assert.Equal(c, strings.TrimSpace(out), "/bin/sh -c echo "+repo)
106 106
 	}
107 107
 }
... ...
@@ -116,7 +117,7 @@ func (s *DockerSchema1RegistrySuite) TestConcurrentPullWholeRepo(c *testing.T) {
116 116
 
117 117
 // testConcurrentFailingPull tries a concurrent pull that doesn't succeed.
118 118
 func testConcurrentFailingPull(c *testing.T) {
119
-	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
119
+	const imgRepo = privateRegistryURL + "/dockercli/busybox"
120 120
 
121 121
 	// Run multiple pulls concurrently
122 122
 	numPulls := 3
... ...
@@ -124,7 +125,7 @@ func testConcurrentFailingPull(c *testing.T) {
124 124
 
125 125
 	for i := 0; i != numPulls; i++ {
126 126
 		go func() {
127
-			result := icmd.RunCommand(dockerBinary, "pull", repoName+":asdfasdf")
127
+			result := icmd.RunCommand(dockerBinary, "pull", imgRepo+":asdfasdf")
128 128
 			results <- result.Error
129 129
 		}()
130 130
 	}
... ...
@@ -148,11 +149,11 @@ func (s *DockerSchema1RegistrySuite) TestConcurrentFailingPull(c *testing.T) {
148 148
 // testConcurrentPullMultipleTags pulls multiple tags from the same repo
149 149
 // concurrently.
150 150
 func testConcurrentPullMultipleTags(c *testing.T) {
151
-	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
151
+	const imgRepo = privateRegistryURL + "/dockercli/busybox"
152 152
 
153 153
 	var repos []string
154 154
 	for _, tag := range []string{"recent", "fresh", "todays"} {
155
-		repo := fmt.Sprintf("%v:%v", repoName, tag)
155
+		repo := fmt.Sprintf("%v:%v", imgRepo, tag)
156 156
 		buildImageSuccessfully(c, repo, build.WithDockerfile(fmt.Sprintf(`
157 157
 		    FROM busybox
158 158
 		    ENTRYPOINT ["/bin/echo"]
... ...
@@ -160,13 +161,13 @@ func testConcurrentPullMultipleTags(c *testing.T) {
160 160
 		    ENV BAR bar
161 161
 		    CMD echo %s
162 162
 		`, repo)))
163
-		dockerCmd(c, "push", repo)
163
+		cli.DockerCmd(c, "push", repo)
164 164
 		repos = append(repos, repo)
165 165
 	}
166 166
 
167 167
 	// Clear local images store.
168 168
 	args := append([]string{"rmi"}, repos...)
169
-	dockerCmd(c, args...)
169
+	cli.DockerCmd(c, args...)
170 170
 
171 171
 	// Re-pull individual tags, in parallel
172 172
 	results := make(chan error, len(repos))
... ...
@@ -187,8 +188,8 @@ func testConcurrentPullMultipleTags(c *testing.T) {
187 187
 
188 188
 	// Ensure all tags were pulled successfully
189 189
 	for _, repo := range repos {
190
-		dockerCmd(c, "inspect", repo)
191
-		out, _ := dockerCmd(c, "run", "--rm", repo)
190
+		cli.DockerCmd(c, "inspect", repo)
191
+		out := cli.DockerCmd(c, "run", "--rm", repo).Combined()
192 192
 		assert.Equal(c, strings.TrimSpace(out), "/bin/sh -c echo "+repo)
193 193
 	}
194 194
 }
... ...
@@ -204,8 +205,8 @@ func (s *DockerSchema1RegistrySuite) TestConcurrentPullMultipleTags(c *testing.T
204 204
 // testPullIDStability verifies that pushing an image and pulling it back
205 205
 // preserves the image ID.
206 206
 func testPullIDStability(c *testing.T) {
207
-	derivedImage := privateRegistryURL + "/dockercli/id-stability"
208
-	baseImage := "busybox"
207
+	const derivedImage = privateRegistryURL + "/dockercli/id-stability"
208
+	const baseImage = "busybox"
209 209
 
210 210
 	buildImageSuccessfully(c, derivedImage, build.WithDockerfile(fmt.Sprintf(`
211 211
 	    FROM %s
... ...
@@ -216,10 +217,10 @@ func testPullIDStability(c *testing.T) {
216 216
 	`, baseImage, derivedImage)))
217 217
 
218 218
 	originalID := getIDByName(c, derivedImage)
219
-	dockerCmd(c, "push", derivedImage)
219
+	cli.DockerCmd(c, "push", derivedImage)
220 220
 
221 221
 	// Pull
222
-	out, _ := dockerCmd(c, "pull", derivedImage)
222
+	out := cli.DockerCmd(c, "pull", derivedImage).Combined()
223 223
 	if strings.Contains(out, "Pull complete") {
224 224
 		c.Fatalf("repull redownloaded a layer: %s", out)
225 225
 	}
... ...
@@ -231,24 +232,23 @@ func testPullIDStability(c *testing.T) {
231 231
 	}
232 232
 
233 233
 	// Make sure the image runs correctly
234
-	out, _ = dockerCmd(c, "run", "--rm", derivedImage)
234
+	out = cli.DockerCmd(c, "run", "--rm", derivedImage).Combined()
235 235
 	if strings.TrimSpace(out) != derivedImage {
236 236
 		c.Fatalf("expected %s; got %s", derivedImage, out)
237 237
 	}
238 238
 
239 239
 	// Confirm that repushing and repulling does not change the computed ID
240
-	dockerCmd(c, "push", derivedImage)
241
-	dockerCmd(c, "rmi", derivedImage)
242
-	dockerCmd(c, "pull", derivedImage)
240
+	cli.DockerCmd(c, "push", derivedImage)
241
+	cli.DockerCmd(c, "rmi", derivedImage)
242
+	cli.DockerCmd(c, "pull", derivedImage)
243 243
 
244 244
 	derivedIDAfterPull = getIDByName(c, derivedImage)
245
-
246 245
 	if derivedIDAfterPull != originalID {
247 246
 		c.Fatal("image's ID unexpectedly changed after a repush/repull")
248 247
 	}
249 248
 
250 249
 	// Make sure the image still runs
251
-	out, _ = dockerCmd(c, "run", "--rm", derivedImage)
250
+	out = cli.DockerCmd(c, "run", "--rm", derivedImage).Combined()
252 251
 	if strings.TrimSpace(out) != derivedImage {
253 252
 		c.Fatalf("expected %s; got %s", derivedImage, out)
254 253
 	}
... ...
@@ -264,14 +264,14 @@ func (s *DockerSchema1RegistrySuite) TestPullIDStability(c *testing.T) {
264 264
 
265 265
 // #21213
266 266
 func testPullNoLayers(c *testing.T) {
267
-	repoName := fmt.Sprintf("%v/dockercli/scratch", privateRegistryURL)
267
+	const imgRepo = privateRegistryURL + "/dockercli/scratch"
268 268
 
269
-	buildImageSuccessfully(c, repoName, build.WithDockerfile(`
269
+	buildImageSuccessfully(c, imgRepo, build.WithDockerfile(`
270 270
 	FROM scratch
271 271
 	ENV foo bar`))
272
-	dockerCmd(c, "push", repoName)
273
-	dockerCmd(c, "rmi", repoName)
274
-	dockerCmd(c, "pull", repoName)
272
+	cli.DockerCmd(c, "push", imgRepo)
273
+	cli.DockerCmd(c, "rmi", imgRepo)
274
+	cli.DockerCmd(c, "pull", imgRepo)
275 275
 }
276 276
 
277 277
 func (s *DockerRegistrySuite) TestPullNoLayers(c *testing.T) {
... ...
@@ -348,7 +348,7 @@ func (s *DockerRegistrySuite) TestPullManifestList(c *testing.T) {
348 348
 	assert.NilError(c, err, "error writing tag link")
349 349
 
350 350
 	// Verify that the image can be pulled through the manifest list.
351
-	out, _ := dockerCmd(c, "pull", repoName)
351
+	out := cli.DockerCmd(c, "pull", repoName).Combined()
352 352
 
353 353
 	// The pull output includes "Digest: <digest>", so find that
354 354
 	matches := digestRegex.FindStringSubmatch(out)
... ...
@@ -359,9 +359,9 @@ func (s *DockerRegistrySuite) TestPullManifestList(c *testing.T) {
359 359
 	assert.Equal(c, manifestListDigest.String(), pullDigest)
360 360
 
361 361
 	// Was the image actually created?
362
-	dockerCmd(c, "inspect", repoName)
362
+	cli.DockerCmd(c, "inspect", repoName)
363 363
 
364
-	dockerCmd(c, "rmi", repoName)
364
+	cli.DockerCmd(c, "rmi", repoName)
365 365
 }
366 366
 
367 367
 // #23100
... ...
@@ -375,7 +375,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithSchem
375 375
 	testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
376 376
 	c.Setenv("PATH", testPath)
377 377
 
378
-	repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
378
+	const imgRepo = privateRegistryURL + "/dockercli/busybox:authtest"
379 379
 
380 380
 	tmp, err := os.MkdirTemp("", "integration-cli-")
381 381
 	assert.NilError(c, err)
... ...
@@ -386,25 +386,25 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithSchem
386 386
 	err = os.WriteFile(configPath, []byte(externalAuthConfig), 0o644)
387 387
 	assert.NilError(c, err)
388 388
 
389
-	dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
389
+	cli.DockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
390 390
 
391 391
 	b, err := os.ReadFile(configPath)
392 392
 	assert.NilError(c, err)
393 393
 	assert.Assert(c, !strings.Contains(string(b), `"auth":`))
394
-	dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
395
-	dockerCmd(c, "--config", tmp, "push", repoName)
394
+	cli.DockerCmd(c, "--config", tmp, "tag", "busybox", imgRepo)
395
+	cli.DockerCmd(c, "--config", tmp, "push", imgRepo)
396 396
 
397
-	dockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
398
-	dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), "https://"+privateRegistryURL)
399
-	dockerCmd(c, "--config", tmp, "pull", repoName)
397
+	cli.DockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
398
+	cli.DockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), "https://"+privateRegistryURL)
399
+	cli.DockerCmd(c, "--config", tmp, "pull", imgRepo)
400 400
 
401 401
 	// likewise push should work
402 402
 	repoName2 := fmt.Sprintf("%v/dockercli/busybox:nocreds", privateRegistryURL)
403
-	dockerCmd(c, "tag", repoName, repoName2)
404
-	dockerCmd(c, "--config", tmp, "push", repoName2)
403
+	cli.DockerCmd(c, "tag", imgRepo, repoName2)
404
+	cli.DockerCmd(c, "--config", tmp, "push", repoName2)
405 405
 
406 406
 	// logout should work w scheme also because it will be stripped
407
-	dockerCmd(c, "--config", tmp, "logout", "https://"+privateRegistryURL)
407
+	cli.DockerCmd(c, "--config", tmp, "logout", "https://"+privateRegistryURL)
408 408
 }
409 409
 
410 410
 func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *testing.T) {
... ...
@@ -417,7 +417,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *testing.T)
417 417
 	testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
418 418
 	c.Setenv("PATH", testPath)
419 419
 
420
-	repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
420
+	const imgRepo = privateRegistryURL + "/dockercli/busybox:authtest"
421 421
 
422 422
 	tmp, err := os.MkdirTemp("", "integration-cli-")
423 423
 	assert.NilError(c, err)
... ...
@@ -428,34 +428,34 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *testing.T)
428 428
 	err = os.WriteFile(configPath, []byte(externalAuthConfig), 0o644)
429 429
 	assert.NilError(c, err)
430 430
 
431
-	dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
431
+	cli.DockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
432 432
 
433 433
 	b, err := os.ReadFile(configPath)
434 434
 	assert.NilError(c, err)
435 435
 	assert.Assert(c, !strings.Contains(string(b), `"auth":`))
436
-	dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
437
-	dockerCmd(c, "--config", tmp, "push", repoName)
436
+	cli.DockerCmd(c, "--config", tmp, "tag", "busybox", imgRepo)
437
+	cli.DockerCmd(c, "--config", tmp, "push", imgRepo)
438 438
 
439
-	dockerCmd(c, "--config", tmp, "pull", repoName)
439
+	cli.DockerCmd(c, "--config", tmp, "pull", imgRepo)
440 440
 }
441 441
 
442 442
 // TestRunImplicitPullWithNoTag should pull implicitly only the default tag (latest)
443 443
 func (s *DockerRegistrySuite) TestRunImplicitPullWithNoTag(c *testing.T) {
444 444
 	testRequires(c, DaemonIsLinux)
445
-	repo := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
446
-	repoTag1 := fmt.Sprintf("%v:latest", repo)
447
-	repoTag2 := fmt.Sprintf("%v:t1", repo)
445
+	const imgRepo = privateRegistryURL + "/dockercli/busybox"
446
+	const repoTag1 = imgRepo + ":latest"
447
+	const repoTag2 = imgRepo + ":t1"
448 448
 	// tag the image and upload it to the private registry
449
-	dockerCmd(c, "tag", "busybox", repoTag1)
450
-	dockerCmd(c, "tag", "busybox", repoTag2)
451
-	dockerCmd(c, "push", repo)
452
-	dockerCmd(c, "rmi", repoTag1)
453
-	dockerCmd(c, "rmi", repoTag2)
454
-
455
-	out, _ := dockerCmd(c, "run", repo)
456
-	assert.Assert(c, strings.Contains(out, fmt.Sprintf("Unable to find image '%s:latest' locally", repo)))
449
+	cli.DockerCmd(c, "tag", "busybox", repoTag1)
450
+	cli.DockerCmd(c, "tag", "busybox", repoTag2)
451
+	cli.DockerCmd(c, "push", imgRepo)
452
+	cli.DockerCmd(c, "rmi", repoTag1)
453
+	cli.DockerCmd(c, "rmi", repoTag2)
454
+
455
+	out := cli.DockerCmd(c, "run", imgRepo).Combined()
456
+	assert.Assert(c, strings.Contains(out, fmt.Sprintf("Unable to find image '%s:latest' locally", imgRepo)))
457 457
 	// There should be only one line for repo, the one with repo:latest
458
-	outImageCmd, _ := dockerCmd(c, "images", repo)
458
+	outImageCmd := cli.DockerCmd(c, "images", imgRepo).Stdout()
459 459
 	splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n")
460 460
 	assert.Equal(c, len(splitOutImageCmd), 2)
461 461
 }
... ...
@@ -181,9 +181,9 @@ func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *testing.T) {
181 181
 // Ref: docker/docker#15589
182 182
 func (s *DockerHubPullSuite) TestPullClientDisconnect(c *testing.T) {
183 183
 	testRequires(c, DaemonIsLinux)
184
-	repoName := "hello-world:latest"
184
+	const imgRepo = "hello-world:latest"
185 185
 
186
-	pullCmd := s.MakeCmd("pull", repoName)
186
+	pullCmd := s.MakeCmd("pull", imgRepo)
187 187
 	stdout, err := pullCmd.StdoutPipe()
188 188
 	assert.NilError(c, err)
189 189
 	err = pullCmd.Start()
... ...
@@ -199,7 +199,7 @@ func (s *DockerHubPullSuite) TestPullClientDisconnect(c *testing.T) {
199 199
 	assert.NilError(c, err)
200 200
 
201 201
 	time.Sleep(2 * time.Second)
202
-	_, err = s.CmdWithError("inspect", repoName)
202
+	_, err = s.CmdWithError("inspect", imgRepo)
203 203
 	assert.ErrorContains(c, err, "", "image was pulled after client disconnected")
204 204
 }
205 205
 
... ...
@@ -13,6 +13,7 @@ import (
13 13
 
14 14
 	"github.com/distribution/reference"
15 15
 	"github.com/docker/docker/api/types/versions"
16
+	"github.com/docker/docker/integration-cli/cli"
16 17
 	"github.com/docker/docker/integration-cli/cli/build"
17 18
 	"gotest.tools/v3/assert"
18 19
 	"gotest.tools/v3/icmd"
... ...
@@ -31,11 +32,11 @@ func (s *DockerCLIPushSuite) OnTimeout(c *testing.T) {
31 31
 }
32 32
 
33 33
 func (s *DockerRegistrySuite) TestPushBusyboxImage(c *testing.T) {
34
-	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
34
+	const imgRepo = privateRegistryURL + "/dockercli/busybox"
35 35
 	// tag the image to upload it to the private registry
36
-	dockerCmd(c, "tag", "busybox", repoName)
36
+	cli.DockerCmd(c, "tag", "busybox", imgRepo)
37 37
 	// push the image to the registry
38
-	dockerCmd(c, "push", repoName)
38
+	cli.DockerCmd(c, "push", imgRepo)
39 39
 }
40 40
 
41 41
 // pushing an image without a prefix should throw an error
... ...
@@ -45,44 +46,44 @@ func (s *DockerCLIPushSuite) TestPushUnprefixedRepo(c *testing.T) {
45 45
 }
46 46
 
47 47
 func (s *DockerRegistrySuite) TestPushUntagged(c *testing.T) {
48
-	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
49
-	expected := "An image does not exist locally with the tag"
48
+	const imgRepo = privateRegistryURL + "/dockercli/busybox"
50 49
 
51
-	out, _, err := dockerCmdWithError("push", repoName)
50
+	out, _, err := dockerCmdWithError("push", imgRepo)
52 51
 	assert.ErrorContains(c, err, "", "pushing the image to the private registry should have failed: output %q", out)
52
+	const expected = "An image does not exist locally with the tag"
53 53
 	assert.Assert(c, strings.Contains(out, expected), "pushing the image failed")
54 54
 }
55 55
 
56 56
 func (s *DockerRegistrySuite) TestPushBadTag(c *testing.T) {
57
-	repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
58
-	expected := "does not exist"
57
+	const imgRepo = privateRegistryURL + "/dockercli/busybox:latest"
59 58
 
60
-	out, _, err := dockerCmdWithError("push", repoName)
59
+	out, _, err := dockerCmdWithError("push", imgRepo)
61 60
 	assert.ErrorContains(c, err, "", "pushing the image to the private registry should have failed: output %q", out)
61
+	const expected = "does not exist"
62 62
 	assert.Assert(c, strings.Contains(out, expected), "pushing the image failed")
63 63
 }
64 64
 
65 65
 func (s *DockerRegistrySuite) TestPushMultipleTags(c *testing.T) {
66
-	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
67
-	repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL)
68
-	repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
66
+	const imgRepo = privateRegistryURL + "/dockercli/busybox"
67
+	const repoTag1 = imgRepo + ":t1"
68
+	const repoTag2 = imgRepo + ":t2"
69 69
 	// tag the image and upload it to the private registry
70
-	dockerCmd(c, "tag", "busybox", repoTag1)
71
-	dockerCmd(c, "tag", "busybox", repoTag2)
70
+	cli.DockerCmd(c, "tag", "busybox", repoTag1)
71
+	cli.DockerCmd(c, "tag", "busybox", repoTag2)
72 72
 
73 73
 	args := []string{"push"}
74 74
 	if versions.GreaterThanOrEqualTo(DockerCLIVersion(c), "20.10.0") {
75 75
 		// 20.10 CLI removed implicit push all tags and requires the "--all" flag
76 76
 		args = append(args, "--all-tags")
77 77
 	}
78
-	args = append(args, repoName)
78
+	args = append(args, imgRepo)
79 79
 
80
-	dockerCmd(c, args...)
80
+	cli.DockerCmd(c, args...)
81 81
 
82 82
 	imageAlreadyExists := ": Image already exists"
83 83
 
84 84
 	// Ensure layer list is equivalent for repoTag1 and repoTag2
85
-	out1, _ := dockerCmd(c, "push", repoTag1)
85
+	out1 := cli.DockerCmd(c, "push", repoTag1).Combined()
86 86
 	var out1Lines []string
87 87
 	for _, outputLine := range strings.Split(out1, "\n") {
88 88
 		if strings.Contains(outputLine, imageAlreadyExists) {
... ...
@@ -90,7 +91,7 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *testing.T) {
90 90
 		}
91 91
 	}
92 92
 
93
-	out2, _ := dockerCmd(c, "push", repoTag2)
93
+	out2 := cli.DockerCmd(c, "push", repoTag2).Combined()
94 94
 	var out2Lines []string
95 95
 	for _, outputLine := range strings.Split(out2, "\n") {
96 96
 		if strings.Contains(outputLine, imageAlreadyExists) {
... ...
@@ -101,7 +102,8 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *testing.T) {
101 101
 }
102 102
 
103 103
 func (s *DockerRegistrySuite) TestPushEmptyLayer(c *testing.T) {
104
-	repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
104
+	const imgRepo = privateRegistryURL + "/dockercli/emptylayer"
105
+
105 106
 	emptyTarball, err := os.CreateTemp("", "empty_tarball")
106 107
 	assert.NilError(c, err, "Unable to create test file")
107 108
 
... ...
@@ -114,23 +116,23 @@ func (s *DockerRegistrySuite) TestPushEmptyLayer(c *testing.T) {
114 114
 	defer freader.Close()
115 115
 
116 116
 	icmd.RunCmd(icmd.Cmd{
117
-		Command: []string{dockerBinary, "import", "-", repoName},
117
+		Command: []string{dockerBinary, "import", "-", imgRepo},
118 118
 		Stdin:   freader,
119 119
 	}).Assert(c, icmd.Success)
120 120
 
121 121
 	// Now verify we can push it
122
-	out, _, err := dockerCmdWithError("push", repoName)
122
+	out, _, err := dockerCmdWithError("push", imgRepo)
123 123
 	assert.NilError(c, err, "pushing the image to the private registry has failed: %s", out)
124 124
 }
125 125
 
126 126
 // TestConcurrentPush pushes multiple tags to the same repo
127 127
 // concurrently.
128 128
 func (s *DockerRegistrySuite) TestConcurrentPush(c *testing.T) {
129
-	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
129
+	const imgRepo = privateRegistryURL + "/dockercli/busybox"
130 130
 
131 131
 	var repos []string
132 132
 	for _, tag := range []string{"push1", "push2", "push3"} {
133
-		repo := fmt.Sprintf("%v:%v", repoName, tag)
133
+		repo := fmt.Sprintf("%v:%v", imgRepo, tag)
134 134
 		buildImageSuccessfully(c, repo, build.WithDockerfile(fmt.Sprintf(`
135 135
 	FROM busybox
136 136
 	ENTRYPOINT ["/bin/echo"]
... ...
@@ -158,21 +160,22 @@ func (s *DockerRegistrySuite) TestConcurrentPush(c *testing.T) {
158 158
 
159 159
 	// Clear local images store.
160 160
 	args := append([]string{"rmi"}, repos...)
161
-	dockerCmd(c, args...)
161
+	cli.DockerCmd(c, args...)
162 162
 
163 163
 	// Re-pull and run individual tags, to make sure pushes succeeded
164 164
 	for _, repo := range repos {
165
-		dockerCmd(c, "pull", repo)
166
-		dockerCmd(c, "inspect", repo)
167
-		out, _ := dockerCmd(c, "run", "--rm", repo)
165
+		cli.DockerCmd(c, "pull", repo)
166
+		cli.DockerCmd(c, "inspect", repo)
167
+		out := cli.DockerCmd(c, "run", "--rm", repo).Combined()
168 168
 		assert.Equal(c, strings.TrimSpace(out), "/bin/sh -c echo "+repo)
169 169
 	}
170 170
 }
171 171
 
172 172
 func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *testing.T) {
173
-	sourceRepoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
173
+	const sourceRepoName = privateRegistryURL + "/dockercli/busybox"
174
+
174 175
 	// tag the image to upload it to the private registry
175
-	dockerCmd(c, "tag", "busybox", sourceRepoName)
176
+	cli.DockerCmd(c, "tag", "busybox", sourceRepoName)
176 177
 	// push the image to the registry
177 178
 	out1, _, err := dockerCmdWithError("push", sourceRepoName)
178 179
 	assert.NilError(c, err, "pushing the image to the private registry has failed: %s", out1)
... ...
@@ -182,9 +185,10 @@ func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *testing.T) {
182 182
 	digest1 := reference.DigestRegexp.FindString(out1)
183 183
 	assert.Assert(c, len(digest1) > 0, "no digest found for pushed manifest")
184 184
 
185
-	destRepoName := fmt.Sprintf("%v/dockercli/crossrepopush", privateRegistryURL)
185
+	const destRepoName = privateRegistryURL + "/dockercli/crossrepopush"
186
+
186 187
 	// retag the image to upload the same layers to another repo in the same registry
187
-	dockerCmd(c, "tag", "busybox", destRepoName)
188
+	cli.DockerCmd(c, "tag", "busybox", destRepoName)
188 189
 	// push the image to the registry
189 190
 	out2, _, err := dockerCmdWithError("push", destRepoName)
190 191
 	assert.NilError(c, err, "pushing the image to the private registry has failed: %s", out2)
... ...
@@ -205,16 +209,16 @@ func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *testing.T) {
205 205
 	assert.Equal(c, digest3, digest2)
206 206
 
207 207
 	// ensure that we can pull and run the cross-repo-pushed repository
208
-	dockerCmd(c, "rmi", destRepoName)
209
-	dockerCmd(c, "pull", destRepoName)
210
-	out4, _ := dockerCmd(c, "run", destRepoName, "echo", "-n", "hello world")
208
+	cli.DockerCmd(c, "rmi", destRepoName)
209
+	cli.DockerCmd(c, "pull", destRepoName)
210
+	out4 := cli.DockerCmd(c, "run", destRepoName, "echo", "-n", "hello world").Combined()
211 211
 	assert.Equal(c, out4, "hello world")
212 212
 }
213 213
 
214 214
 func (s *DockerRegistryAuthHtpasswdSuite) TestPushNoCredentialsNoRetry(c *testing.T) {
215
-	repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
216
-	dockerCmd(c, "tag", "busybox", repoName)
217
-	out, _, err := dockerCmdWithError("push", repoName)
215
+	const imgRepo = privateRegistryURL + "/busybox"
216
+	cli.DockerCmd(c, "tag", "busybox", imgRepo)
217
+	out, _, err := dockerCmdWithError("push", imgRepo)
218 218
 	assert.ErrorContains(c, err, "", out)
219 219
 	assert.Assert(c, !strings.Contains(out, "Retrying"))
220 220
 	assert.Assert(c, strings.Contains(out, "no basic auth credentials"))
... ...
@@ -223,9 +227,10 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPushNoCredentialsNoRetry(c *testin
223 223
 // This may be flaky but it's needed not to regress on unauthorized push, see #21054
224 224
 func (s *DockerCLIPushSuite) TestPushToCentralRegistryUnauthorized(c *testing.T) {
225 225
 	testRequires(c, Network)
226
-	repoName := "test/busybox"
227
-	dockerCmd(c, "tag", "busybox", repoName)
228
-	out, _, err := dockerCmdWithError("push", repoName)
226
+
227
+	const imgRepo = "test/busybox"
228
+	cli.DockerCmd(c, "tag", "busybox", imgRepo)
229
+	out, _, err := dockerCmdWithError("push", imgRepo)
229 230
 	assert.ErrorContains(c, err, "", out)
230 231
 	assert.Assert(c, !strings.Contains(out, "Retrying"))
231 232
 }
... ...
@@ -252,9 +257,10 @@ func (s *DockerRegistryAuthTokenSuite) TestPushTokenServiceUnauthResponse(c *tes
252 252
 	ts := getTestTokenService(http.StatusUnauthorized, `{"errors": [{"Code":"UNAUTHORIZED", "message": "a message", "detail": null}]}`, 0)
253 253
 	defer ts.Close()
254 254
 	s.setupRegistryWithTokenService(c, ts.URL)
255
-	repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
256
-	dockerCmd(c, "tag", "busybox", repoName)
257
-	out, _, err := dockerCmdWithError("push", repoName)
255
+
256
+	const imgRepo = privateRegistryURL + "/busybox"
257
+	cli.DockerCmd(c, "tag", "busybox", imgRepo)
258
+	out, _, err := dockerCmdWithError("push", imgRepo)
258 259
 	assert.ErrorContains(c, err, "", out)
259 260
 	assert.Assert(c, !strings.Contains(out, "Retrying"))
260 261
 	assert.Assert(c, strings.Contains(out, "unauthorized: a message"))
... ...
@@ -264,9 +270,10 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse
264 264
 	ts := getTestTokenService(http.StatusUnauthorized, `{"error": "unauthorized"}`, 0)
265 265
 	defer ts.Close()
266 266
 	s.setupRegistryWithTokenService(c, ts.URL)
267
-	repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
268
-	dockerCmd(c, "tag", "busybox", repoName)
269
-	out, _, err := dockerCmdWithError("push", repoName)
267
+
268
+	const imgRepo = privateRegistryURL + "/busybox"
269
+	cli.DockerCmd(c, "tag", "busybox", imgRepo)
270
+	out, _, err := dockerCmdWithError("push", imgRepo)
270 271
 	assert.ErrorContains(c, err, "", out)
271 272
 	assert.Assert(c, !strings.Contains(out, "Retrying"))
272 273
 	split := strings.Split(out, "\n")
... ...
@@ -277,9 +284,10 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse
277 277
 	ts := getTestTokenService(http.StatusTooManyRequests, `{"errors": [{"code":"TOOMANYREQUESTS","message":"out of tokens"}]}`, 3)
278 278
 	defer ts.Close()
279 279
 	s.setupRegistryWithTokenService(c, ts.URL)
280
-	repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
281
-	dockerCmd(c, "tag", "busybox", repoName)
282
-	out, _, err := dockerCmdWithError("push", repoName)
280
+
281
+	const imgRepo = privateRegistryURL + "/busybox"
282
+	cli.DockerCmd(c, "tag", "busybox", imgRepo)
283
+	out, _, err := dockerCmdWithError("push", imgRepo)
283 284
 	assert.ErrorContains(c, err, "", out)
284 285
 	// TODO: isolate test so that it can be guaranteed that the 503 will trigger xfer retries
285 286
 	// assert.Assert(c, strings.Contains(out, "Retrying"))
... ...
@@ -292,9 +300,10 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse
292 292
 	ts := getTestTokenService(http.StatusForbidden, `no way`, 0)
293 293
 	defer ts.Close()
294 294
 	s.setupRegistryWithTokenService(c, ts.URL)
295
-	repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
296
-	dockerCmd(c, "tag", "busybox", repoName)
297
-	out, _, err := dockerCmdWithError("push", repoName)
295
+
296
+	const imgRepo = privateRegistryURL + "/busybox"
297
+	cli.DockerCmd(c, "tag", "busybox", imgRepo)
298
+	out, _, err := dockerCmdWithError("push", imgRepo)
298 299
 	assert.ErrorContains(c, err, "", out)
299 300
 	assert.Assert(c, !strings.Contains(out, "Retrying"))
300 301
 	split := strings.Split(out, "\n")
... ...
@@ -305,9 +314,10 @@ func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponse
305 305
 	ts := getTestTokenService(http.StatusOK, `{"something": "wrong"}`, 0)
306 306
 	defer ts.Close()
307 307
 	s.setupRegistryWithTokenService(c, ts.URL)
308
-	repoName := fmt.Sprintf("%s/busybox", privateRegistryURL)
309
-	dockerCmd(c, "tag", "busybox", repoName)
310
-	out, _, err := dockerCmdWithError("push", repoName)
308
+
309
+	const imgRepo = privateRegistryURL + "/busybox"
310
+	cli.DockerCmd(c, "tag", "busybox", imgRepo)
311
+	out, _, err := dockerCmdWithError("push", imgRepo)
311 312
 	assert.ErrorContains(c, err, "", out)
312 313
 	assert.Assert(c, !strings.Contains(out, "Retrying"))
313 314
 	split := strings.Split(out, "\n")
... ...
@@ -1,7 +1,6 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"net/http"
6 5
 	"os"
7 6
 	"regexp"
... ...
@@ -80,7 +79,7 @@ func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *testing.T) {
80 80
 	defer reg.Close()
81 81
 
82 82
 	registerUserAgentHandler(reg, &ua)
83
-	repoName := fmt.Sprintf("%s/busybox", reg.URL())
83
+	imgRepo := reg.URL() + "/busybox"
84 84
 
85 85
 	s.d.StartWithBusybox(ctx, c, "--insecure-registry", reg.URL())
86 86
 
... ...
@@ -88,7 +87,7 @@ func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *testing.T) {
88 88
 	assert.NilError(c, err)
89 89
 	defer os.RemoveAll(tmp)
90 90
 
91
-	dockerfile, err := makefile(tmp, fmt.Sprintf("FROM %s", repoName))
91
+	dockerfile, err := makefile(tmp, "FROM "+imgRepo)
92 92
 	assert.NilError(c, err, "Unable to create test dockerfile")
93 93
 
94 94
 	s.d.Cmd("build", "--file", dockerfile, tmp)
... ...
@@ -97,10 +96,10 @@ func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *testing.T) {
97 97
 	s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
98 98
 	regexpCheckUA(c, ua)
99 99
 
100
-	s.d.Cmd("pull", repoName)
100
+	s.d.Cmd("pull", imgRepo)
101 101
 	regexpCheckUA(c, ua)
102 102
 
103
-	s.d.Cmd("tag", "busybox", repoName)
104
-	s.d.Cmd("push", repoName)
103
+	s.d.Cmd("tag", "busybox", imgRepo)
104
+	s.d.Cmd("push", imgRepo)
105 105
 	regexpCheckUA(c, ua)
106 106
 }