From aa123b73d14936eef2d52abef95b9120c070375e Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Fri, 17 Jun 2016 09:18:27 -0700 Subject: [PATCH] Add tests for rmi Add integration test for removing by image id with tag and digest reference to the same repository. Add integration test to ensure only tag to other repository remains after deleting tag with accompanying digest reference. Signed-off-by: Derek McGowan (github: dmcgowan) (cherry picked from commit 5cff374b140b4a836b7082d009bcfe9a6e96f1af) --- integration-cli/docker_cli_by_digest_test.go | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/integration-cli/docker_cli_by_digest_test.go b/integration-cli/docker_cli_by_digest_test.go index 2f71d0f103..b89c76cce3 100644 --- a/integration-cli/docker_cli_by_digest_test.go +++ b/integration-cli/docker_cli_by_digest_test.go @@ -380,9 +380,14 @@ func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) dockerCmd(c, "pull", imageReference) // just in case... + dockerCmd(c, "tag", imageReference, repoName+":sometag") + imageID := inspectField(c, imageReference, "Id") dockerCmd(c, "rmi", imageID) + + _, err = inspectFieldWithError(imageID, "Id") + c.Assert(err, checker.NotNil, check.Commentf("image should have been deleted")) } func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndTag(c *check.C) { @@ -412,6 +417,40 @@ func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndTag(c *check.C) { c.Assert(err, checker.NotNil, check.Commentf("image should have been deleted")) } +func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndMultiRepoTag(c *check.C) { + pushDigest, err := setupImage(c) + c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) + + repo2 := fmt.Sprintf("%s/%s", repoName, "repo2") + + // pull from the registry using the @ reference + imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) + dockerCmd(c, "pull", imageReference) + + imageID := inspectField(c, imageReference, "Id") + + repoTag := repoName + ":sometag" + repoTag2 := repo2 + ":othertag" + dockerCmd(c, "tag", imageReference, repoTag) + dockerCmd(c, "tag", imageReference, repoTag2) + + dockerCmd(c, "rmi", repoTag) + + // rmi should have deleted repoTag and image reference, but left repoTag2 + inspectField(c, repoTag2, "Id") + _, err = inspectFieldWithError(imageReference, "Id") + c.Assert(err, checker.NotNil, check.Commentf("image digest reference should have been removed")) + + _, err = inspectFieldWithError(repoTag, "Id") + c.Assert(err, checker.NotNil, check.Commentf("image tag reference should have been removed")) + + dockerCmd(c, "rmi", repoTag2) + + // rmi should have deleted the tag, the digest reference, and the image itself + _, err = inspectFieldWithError(imageID, "Id") + c.Assert(err, checker.NotNil, check.Commentf("image should have been deleted")) +} + // TestPullFailsWithAlteredManifest tests that a `docker pull` fails when // we have modified a manifest blob and its digest cannot be verified. // This is the schema2 version of the test.