Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -31,59 +31,58 @@ func (s *DockerCLIRmiSuite) TestRmiWithContainerFails(c *testing.T) {
|
| 31 | 31 |
errSubstr := "is using it" |
| 32 | 32 |
|
| 33 | 33 |
// create a container |
| 34 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "true") |
|
| 35 |
- |
|
| 36 |
- cleanedContainerID := strings.TrimSpace(out) |
|
| 34 |
+ cID := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout() |
|
| 35 |
+ cID = strings.TrimSpace(cID) |
|
| 37 | 36 |
|
| 38 | 37 |
// try to delete the image |
| 39 | 38 |
out, _, err := dockerCmdWithError("rmi", "busybox")
|
| 40 | 39 |
// Container is using image, should not be able to rmi |
| 41 | 40 |
assert.ErrorContains(c, err, "") |
| 42 | 41 |
// Container is using image, error message should contain errSubstr |
| 43 |
- assert.Assert(c, strings.Contains(out, errSubstr), "Container: %q", cleanedContainerID) |
|
| 42 |
+ assert.Assert(c, strings.Contains(out, errSubstr), "Container: %q", cID) |
|
| 44 | 43 |
// make sure it didn't delete the busybox name |
| 45 |
- images, _ := dockerCmd(c, "images") |
|
| 44 |
+ images := cli.DockerCmd(c, "images").Stdout() |
|
| 46 | 45 |
// The name 'busybox' should not have been removed from images |
| 47 | 46 |
assert.Assert(c, strings.Contains(images, "busybox")) |
| 48 | 47 |
} |
| 49 | 48 |
|
| 50 | 49 |
func (s *DockerCLIRmiSuite) TestRmiTag(c *testing.T) {
|
| 51 |
- imagesBefore, _ := dockerCmd(c, "images", "-a") |
|
| 52 |
- dockerCmd(c, "tag", "busybox", "utest:tag1") |
|
| 53 |
- dockerCmd(c, "tag", "busybox", "utest/docker:tag2") |
|
| 54 |
- dockerCmd(c, "tag", "busybox", "utest:5000/docker:tag3") |
|
| 50 |
+ imagesBefore := cli.DockerCmd(c, "images", "-a").Stdout() |
|
| 51 |
+ cli.DockerCmd(c, "tag", "busybox", "utest:tag1") |
|
| 52 |
+ cli.DockerCmd(c, "tag", "busybox", "utest/docker:tag2") |
|
| 53 |
+ cli.DockerCmd(c, "tag", "busybox", "utest:5000/docker:tag3") |
|
| 55 | 54 |
{
|
| 56 |
- imagesAfter, _ := dockerCmd(c, "images", "-a") |
|
| 55 |
+ imagesAfter := cli.DockerCmd(c, "images", "-a").Stdout() |
|
| 57 | 56 |
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+3, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
| 58 | 57 |
} |
| 59 |
- dockerCmd(c, "rmi", "utest/docker:tag2") |
|
| 58 |
+ cli.DockerCmd(c, "rmi", "utest/docker:tag2") |
|
| 60 | 59 |
{
|
| 61 |
- imagesAfter, _ := dockerCmd(c, "images", "-a") |
|
| 60 |
+ imagesAfter := cli.DockerCmd(c, "images", "-a").Stdout() |
|
| 62 | 61 |
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+2, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
| 63 | 62 |
} |
| 64 |
- dockerCmd(c, "rmi", "utest:5000/docker:tag3") |
|
| 63 |
+ cli.DockerCmd(c, "rmi", "utest:5000/docker:tag3") |
|
| 65 | 64 |
{
|
| 66 |
- imagesAfter, _ := dockerCmd(c, "images", "-a") |
|
| 65 |
+ imagesAfter := cli.DockerCmd(c, "images", "-a").Stdout() |
|
| 67 | 66 |
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+1, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
| 68 | 67 |
} |
| 69 |
- dockerCmd(c, "rmi", "utest:tag1") |
|
| 68 |
+ cli.DockerCmd(c, "rmi", "utest:tag1") |
|
| 70 | 69 |
{
|
| 71 |
- imagesAfter, _ := dockerCmd(c, "images", "-a") |
|
| 70 |
+ imagesAfter := cli.DockerCmd(c, "images", "-a").Stdout() |
|
| 72 | 71 |
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n"), fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
|
| 73 | 72 |
} |
| 74 | 73 |
} |
| 75 | 74 |
|
| 76 | 75 |
func (s *DockerCLIRmiSuite) TestRmiImgIDMultipleTag(c *testing.T) {
|
| 77 |
- out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'").Combined() |
|
| 78 |
- containerID := strings.TrimSpace(out) |
|
| 76 |
+ cID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'").Combined() |
|
| 77 |
+ cID = strings.TrimSpace(cID) |
|
| 79 | 78 |
|
| 80 | 79 |
// Wait for it to exit as cannot commit a running container on Windows, and |
| 81 | 80 |
// it will take a few seconds to exit |
| 82 | 81 |
if testEnv.DaemonInfo.OSType == "windows" {
|
| 83 |
- cli.WaitExited(c, containerID, 60*time.Second) |
|
| 82 |
+ cli.WaitExited(c, cID, 60*time.Second) |
|
| 84 | 83 |
} |
| 85 | 84 |
|
| 86 |
- cli.DockerCmd(c, "commit", containerID, "busybox-one") |
|
| 85 |
+ cli.DockerCmd(c, "commit", cID, "busybox-one") |
|
| 87 | 86 |
|
| 88 | 87 |
imagesBefore := cli.DockerCmd(c, "images", "-a").Combined() |
| 89 | 88 |
cli.DockerCmd(c, "tag", "busybox-one", "busybox-one:tag1") |
| ... | ... |
@@ -96,17 +95,17 @@ func (s *DockerCLIRmiSuite) TestRmiImgIDMultipleTag(c *testing.T) {
|
| 96 | 96 |
imgID := inspectField(c, "busybox-one:tag1", "Id") |
| 97 | 97 |
|
| 98 | 98 |
// run a container with the image |
| 99 |
- out = runSleepingContainerInImage(c, "busybox-one") |
|
| 100 |
- containerID = strings.TrimSpace(out) |
|
| 99 |
+ cID = runSleepingContainerInImage(c, "busybox-one") |
|
| 100 |
+ cID = strings.TrimSpace(cID) |
|
| 101 | 101 |
|
| 102 | 102 |
// first checkout without force it fails |
| 103 | 103 |
// rmi tagged in multiple repos should have failed without force |
| 104 | 104 |
cli.Docker(cli.Args("rmi", imgID)).Assert(c, icmd.Expected{
|
| 105 | 105 |
ExitCode: 1, |
| 106 |
- Err: fmt.Sprintf("conflict: unable to delete %s (cannot be forced) - image is being used by running container %s", stringid.TruncateID(imgID), stringid.TruncateID(containerID)),
|
|
| 106 |
+ Err: fmt.Sprintf("conflict: unable to delete %s (cannot be forced) - image is being used by running container %s", stringid.TruncateID(imgID), stringid.TruncateID(cID)),
|
|
| 107 | 107 |
}) |
| 108 | 108 |
|
| 109 |
- cli.DockerCmd(c, "stop", containerID) |
|
| 109 |
+ cli.DockerCmd(c, "stop", cID) |
|
| 110 | 110 |
cli.DockerCmd(c, "rmi", "-f", imgID) |
| 111 | 111 |
|
| 112 | 112 |
imagesAfter = cli.DockerCmd(c, "images", "-a").Combined() |
| ... | ... |
@@ -115,16 +114,16 @@ func (s *DockerCLIRmiSuite) TestRmiImgIDMultipleTag(c *testing.T) {
|
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 | 117 |
func (s *DockerCLIRmiSuite) TestRmiImgIDForce(c *testing.T) {
|
| 118 |
- out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'").Combined() |
|
| 119 |
- containerID := strings.TrimSpace(out) |
|
| 118 |
+ cID := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'").Combined() |
|
| 119 |
+ cID = strings.TrimSpace(cID) |
|
| 120 | 120 |
|
| 121 | 121 |
// Wait for it to exit as cannot commit a running container on Windows, and |
| 122 | 122 |
// it will take a few seconds to exit |
| 123 | 123 |
if testEnv.DaemonInfo.OSType == "windows" {
|
| 124 |
- cli.WaitExited(c, containerID, 60*time.Second) |
|
| 124 |
+ cli.WaitExited(c, cID, 60*time.Second) |
|
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 |
- cli.DockerCmd(c, "commit", containerID, "busybox-test") |
|
| 127 |
+ cli.DockerCmd(c, "commit", cID, "busybox-test") |
|
| 128 | 128 |
|
| 129 | 129 |
imagesBefore := cli.DockerCmd(c, "images", "-a").Combined() |
| 130 | 130 |
cli.DockerCmd(c, "tag", "busybox-test", "utest:tag1") |
| ... | ... |
@@ -158,7 +157,7 @@ func (s *DockerCLIRmiSuite) TestRmiImageIDForceWithRunningContainersAndMultipleT |
| 158 | 158 |
imgID := getIDByName(c, "test-14116") |
| 159 | 159 |
|
| 160 | 160 |
newTag := "newtag" |
| 161 |
- dockerCmd(c, "tag", imgID, newTag) |
|
| 161 |
+ cli.DockerCmd(c, "tag", imgID, newTag) |
|
| 162 | 162 |
runSleepingContainerInImage(c, imgID) |
| 163 | 163 |
|
| 164 | 164 |
out, _, err := dockerCmdWithError("rmi", "-f", imgID)
|
| ... | ... |
@@ -171,11 +170,11 @@ func (s *DockerCLIRmiSuite) TestRmiTagWithExistingContainers(c *testing.T) {
|
| 171 | 171 |
container := "test-delete-tag" |
| 172 | 172 |
newtag := "busybox:newtag" |
| 173 | 173 |
bb := "busybox:latest" |
| 174 |
- dockerCmd(c, "tag", bb, newtag) |
|
| 174 |
+ cli.DockerCmd(c, "tag", bb, newtag) |
|
| 175 | 175 |
|
| 176 |
- dockerCmd(c, "run", "--name", container, bb, "/bin/true") |
|
| 176 |
+ cli.DockerCmd(c, "run", "--name", container, bb, "/bin/true") |
|
| 177 | 177 |
|
| 178 |
- out, _ := dockerCmd(c, "rmi", newtag) |
|
| 178 |
+ out := cli.DockerCmd(c, "rmi", newtag).Combined() |
|
| 179 | 179 |
assert.Equal(c, strings.Count(out, "Untagged: "), 1) |
| 180 | 180 |
} |
| 181 | 181 |
|
| ... | ... |
@@ -188,22 +187,22 @@ func (s *DockerCLIRmiSuite) TestRmiForceWithExistingContainers(c *testing.T) {
|
| 188 | 188 |
MAINTAINER foo`), |
| 189 | 189 |
}).Assert(c, icmd.Success) |
| 190 | 190 |
|
| 191 |
- dockerCmd(c, "run", "--name", "test-force-rmi", image, "/bin/true") |
|
| 191 |
+ cli.DockerCmd(c, "run", "--name", "test-force-rmi", image, "/bin/true") |
|
| 192 | 192 |
|
| 193 |
- dockerCmd(c, "rmi", "-f", image) |
|
| 193 |
+ cli.DockerCmd(c, "rmi", "-f", image) |
|
| 194 | 194 |
} |
| 195 | 195 |
|
| 196 | 196 |
func (s *DockerCLIRmiSuite) TestRmiWithMultipleRepositories(c *testing.T) {
|
| 197 | 197 |
newRepo := "127.0.0.1:5000/busybox" |
| 198 | 198 |
oldRepo := "busybox" |
| 199 | 199 |
newTag := "busybox:test" |
| 200 |
- dockerCmd(c, "tag", oldRepo, newRepo) |
|
| 200 |
+ cli.DockerCmd(c, "tag", oldRepo, newRepo) |
|
| 201 | 201 |
|
| 202 |
- dockerCmd(c, "run", "--name", "test", oldRepo, "touch", "/abcd") |
|
| 202 |
+ cli.DockerCmd(c, "run", "--name", "test", oldRepo, "touch", "/abcd") |
|
| 203 | 203 |
|
| 204 |
- dockerCmd(c, "commit", "test", newTag) |
|
| 204 |
+ cli.DockerCmd(c, "commit", "test", newTag) |
|
| 205 | 205 |
|
| 206 |
- out, _ := dockerCmd(c, "rmi", newTag) |
|
| 206 |
+ out := cli.DockerCmd(c, "rmi", newTag).Combined() |
|
| 207 | 207 |
assert.Assert(c, strings.Contains(out, "Untagged: "+newTag)) |
| 208 | 208 |
} |
| 209 | 209 |
|
| ... | ... |
@@ -214,13 +213,13 @@ func (s *DockerCLIRmiSuite) TestRmiForceWithMultipleRepositories(c *testing.T) {
|
| 214 | 214 |
|
| 215 | 215 |
buildImageSuccessfully(c, tag1, build.WithDockerfile(`FROM busybox |
| 216 | 216 |
MAINTAINER "docker"`)) |
| 217 |
- dockerCmd(c, "tag", tag1, tag2) |
|
| 217 |
+ cli.DockerCmd(c, "tag", tag1, tag2) |
|
| 218 | 218 |
|
| 219 |
- out, _ := dockerCmd(c, "rmi", "-f", tag2) |
|
| 219 |
+ out := cli.DockerCmd(c, "rmi", "-f", tag2).Combined() |
|
| 220 | 220 |
assert.Assert(c, strings.Contains(out, "Untagged: "+tag2)) |
| 221 | 221 |
assert.Assert(c, !strings.Contains(out, "Untagged: "+tag1)) |
| 222 | 222 |
// Check built image still exists |
| 223 |
- images, _ := dockerCmd(c, "images", "-a") |
|
| 223 |
+ images := cli.DockerCmd(c, "images", "-a").Stdout() |
|
| 224 | 224 |
assert.Assert(c, strings.Contains(images, imageName), "Built image missing %q; Images: %q", imageName, images) |
| 225 | 225 |
} |
| 226 | 226 |
|
| ... | ... |
@@ -249,8 +248,8 @@ func (s *DockerCLIRmiSuite) TestRmiContainerImageNotFound(c *testing.T) {
|
| 249 | 249 |
runSleepingContainerInImage(c, imageNames[0]) |
| 250 | 250 |
|
| 251 | 251 |
// Create a stopped container, and then force remove its image. |
| 252 |
- dockerCmd(c, "run", imageNames[1], "true") |
|
| 253 |
- dockerCmd(c, "rmi", "-f", imageIds[1]) |
|
| 252 |
+ cli.DockerCmd(c, "run", imageNames[1], "true") |
|
| 253 |
+ cli.DockerCmd(c, "rmi", "-f", imageIds[1]) |
|
| 254 | 254 |
|
| 255 | 255 |
// Try to remove the image of the running container and see if it fails as expected. |
| 256 | 256 |
out, _, err := dockerCmdWithError("rmi", "-f", imageIds[0])
|
| ... | ... |
@@ -270,35 +269,35 @@ RUN echo 1 #layer1 |
| 270 | 270 |
RUN echo 2 #layer2 |
| 271 | 271 |
` |
| 272 | 272 |
buildImageSuccessfully(c, image, build.WithoutCache, build.WithDockerfile(dockerfile)) |
| 273 |
- out, _ := dockerCmd(c, "history", "-q", image) |
|
| 273 |
+ out := cli.DockerCmd(c, "history", "-q", image).Stdout() |
|
| 274 | 274 |
ids := strings.Split(out, "\n") |
| 275 | 275 |
idToTag := ids[2] |
| 276 | 276 |
|
| 277 | 277 |
// Tag layer0 to "tmp2". |
| 278 | 278 |
newTag := "tmp2" |
| 279 |
- dockerCmd(c, "tag", idToTag, newTag) |
|
| 279 |
+ cli.DockerCmd(c, "tag", idToTag, newTag) |
|
| 280 | 280 |
// Create a container based on "tmp1". |
| 281 |
- dockerCmd(c, "run", "-d", image, "true") |
|
| 281 |
+ cli.DockerCmd(c, "run", "-d", image, "true") |
|
| 282 | 282 |
|
| 283 | 283 |
// See if the "tmp2" can be untagged. |
| 284 |
- out, _ = dockerCmd(c, "rmi", newTag) |
|
| 284 |
+ out = cli.DockerCmd(c, "rmi", newTag).Combined() |
|
| 285 | 285 |
// Expected 1 untagged entry |
| 286 | 286 |
assert.Equal(c, strings.Count(out, "Untagged: "), 1, fmt.Sprintf("out: %s", out))
|
| 287 | 287 |
|
| 288 | 288 |
// Now let's add the tag again and create a container based on it. |
| 289 |
- dockerCmd(c, "tag", idToTag, newTag) |
|
| 290 |
- out, _ = dockerCmd(c, "run", "-d", newTag, "true") |
|
| 291 |
- cid := strings.TrimSpace(out) |
|
| 289 |
+ cli.DockerCmd(c, "tag", idToTag, newTag) |
|
| 290 |
+ cID := cli.DockerCmd(c, "run", "-d", newTag, "true").Stdout() |
|
| 291 |
+ cID = strings.TrimSpace(cID) |
|
| 292 | 292 |
|
| 293 | 293 |
// At this point we have 2 containers, one based on layer2 and another based on layer0. |
| 294 | 294 |
// Try to untag "tmp2" without the -f flag. |
| 295 | 295 |
out, _, err := dockerCmdWithError("rmi", newTag)
|
| 296 | 296 |
// should not be untagged without the -f flag |
| 297 | 297 |
assert.ErrorContains(c, err, "") |
| 298 |
- assert.Assert(c, strings.Contains(out, cid[:12])) |
|
| 298 |
+ assert.Assert(c, strings.Contains(out, cID[:12])) |
|
| 299 | 299 |
assert.Assert(c, strings.Contains(out, "(must force)")) |
| 300 | 300 |
// Add the -f flag and test again. |
| 301 |
- out, _ = dockerCmd(c, "rmi", "-f", newTag) |
|
| 301 |
+ out = cli.DockerCmd(c, "rmi", "-f", newTag).Combined() |
|
| 302 | 302 |
// should be allowed to untag with the -f flag |
| 303 | 303 |
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Untagged: %s:latest", newTag)))
|
| 304 | 304 |
} |
| ... | ... |
@@ -319,24 +318,24 @@ func (*DockerCLIRmiSuite) TestRmiParentImageFail(c *testing.T) {
|
| 319 | 319 |
} |
| 320 | 320 |
|
| 321 | 321 |
func (s *DockerCLIRmiSuite) TestRmiWithParentInUse(c *testing.T) {
|
| 322 |
- out, _ := dockerCmd(c, "create", "busybox") |
|
| 323 |
- cID := strings.TrimSpace(out) |
|
| 322 |
+ cID := cli.DockerCmd(c, "create", "busybox").Stdout() |
|
| 323 |
+ cID = strings.TrimSpace(cID) |
|
| 324 | 324 |
|
| 325 |
- out, _ = dockerCmd(c, "commit", cID) |
|
| 326 |
- imageID := strings.TrimSpace(out) |
|
| 325 |
+ imageID := cli.DockerCmd(c, "commit", cID).Stdout() |
|
| 326 |
+ imageID = strings.TrimSpace(imageID) |
|
| 327 | 327 |
|
| 328 |
- out, _ = dockerCmd(c, "create", imageID) |
|
| 329 |
- cID = strings.TrimSpace(out) |
|
| 328 |
+ cID = cli.DockerCmd(c, "create", imageID).Stdout() |
|
| 329 |
+ cID = strings.TrimSpace(cID) |
|
| 330 | 330 |
|
| 331 |
- out, _ = dockerCmd(c, "commit", cID) |
|
| 332 |
- imageID = strings.TrimSpace(out) |
|
| 331 |
+ imageID = cli.DockerCmd(c, "commit", cID).Stdout() |
|
| 332 |
+ imageID = strings.TrimSpace(imageID) |
|
| 333 | 333 |
|
| 334 |
- dockerCmd(c, "rmi", imageID) |
|
| 334 |
+ cli.DockerCmd(c, "rmi", imageID) |
|
| 335 | 335 |
} |
| 336 | 336 |
|
| 337 | 337 |
// #18873 |
| 338 | 338 |
func (s *DockerCLIRmiSuite) TestRmiByIDHardConflict(c *testing.T) {
|
| 339 |
- dockerCmd(c, "create", "busybox") |
|
| 339 |
+ cli.DockerCmd(c, "create", "busybox") |
|
| 340 | 340 |
|
| 341 | 341 |
imgID := inspectField(c, "busybox:latest", "Id") |
| 342 | 342 |
|