Преглед на файлове

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 <derek@mcgstyle.net> (github: dmcgowan)
(cherry picked from commit 5cff374b140b4a836b7082d009bcfe9a6e96f1af)
Derek McGowan преди 9 години
родител
ревизия
aa123b73d1
променени са 1 файла, в които са добавени 39 реда и са изтрити 0 реда
  1. 39 0
      integration-cli/docker_cli_by_digest_test.go

+ 39 - 0
integration-cli/docker_cli_by_digest_test.go

@@ -380,9 +380,14 @@ func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C)
 	dockerCmd(c, "pull", imageReference)
 	dockerCmd(c, "pull", imageReference)
 	// just in case...
 	// just in case...
 
 
+	dockerCmd(c, "tag", imageReference, repoName+":sometag")
+
 	imageID := inspectField(c, imageReference, "Id")
 	imageID := inspectField(c, imageReference, "Id")
 
 
 	dockerCmd(c, "rmi", imageID)
 	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) {
 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"))
 	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 <name>@<digest> 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
 // TestPullFailsWithAlteredManifest tests that a `docker pull` fails when
 // we have modified a manifest blob and its digest cannot be verified.
 // we have modified a manifest blob and its digest cannot be verified.
 // This is the schema2 version of the test.
 // This is the schema2 version of the test.