Implement DockerRegistrySuite in integration-cli

To avoid manually creating and destroying registrys in tests.

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-04-24 14:16:56 -07:00
parent b76bbae413
commit f696b1071a
5 changed files with 43 additions and 62 deletions

View file

@ -24,6 +24,10 @@ func (s *TimerSuite) TearDownTest(c *check.C) {
fmt.Printf("%-60s%.2f\n", c.TestName(), time.Since(s.start).Seconds()) fmt.Printf("%-60s%.2f\n", c.TestName(), time.Since(s.start).Seconds())
} }
func init() {
check.Suite(&DockerSuite{})
}
type DockerSuite struct { type DockerSuite struct {
TimerSuite TimerSuite
} }
@ -34,4 +38,23 @@ func (s *DockerSuite) TearDownTest(c *check.C) {
s.TimerSuite.TearDownTest(c) s.TimerSuite.TearDownTest(c)
} }
var _ = check.Suite(&DockerSuite{}) func init() {
check.Suite(&DockerRegistrySuite{
ds: &DockerSuite{},
})
}
type DockerRegistrySuite struct {
ds *DockerSuite
reg *testRegistryV2
}
func (s *DockerRegistrySuite) SetUpTest(c *check.C) {
s.reg = setupRegistry(c)
s.ds.SetUpTest(c)
}
func (s *DockerRegistrySuite) TearDownTest(c *check.C) {
s.reg.Close()
s.ds.TearDownTest(c)
}

View file

@ -62,9 +62,7 @@ func setupImageWithTag(tag string) (string, error) {
return pushDigest, nil return pushDigest, nil
} }
func (s *DockerSuite) TestPullByTagDisplaysDigest(c *check.C) { func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) {
defer setupRegistry(c)()
pushDigest, err := setupImage() pushDigest, err := setupImage()
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
@ -88,12 +86,9 @@ func (s *DockerSuite) TestPullByTagDisplaysDigest(c *check.C) {
if pushDigest != pullDigest { if pushDigest != pullDigest {
c.Fatalf("push digest %q didn't match pull digest %q", pushDigest, pullDigest) c.Fatalf("push digest %q didn't match pull digest %q", pushDigest, pullDigest)
} }
} }
func (s *DockerSuite) TestPullByDigest(c *check.C) { func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) {
defer setupRegistry(c)()
pushDigest, err := setupImage() pushDigest, err := setupImage()
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
@ -118,12 +113,9 @@ func (s *DockerSuite) TestPullByDigest(c *check.C) {
if pushDigest != pullDigest { if pushDigest != pullDigest {
c.Fatalf("push digest %q didn't match pull digest %q", pushDigest, pullDigest) c.Fatalf("push digest %q didn't match pull digest %q", pushDigest, pullDigest)
} }
} }
func (s *DockerSuite) TestCreateByDigest(c *check.C) { func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
defer setupRegistry(c)()
pushDigest, err := setupImage() pushDigest, err := setupImage()
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
@ -145,12 +137,9 @@ func (s *DockerSuite) TestCreateByDigest(c *check.C) {
if res != imageReference { if res != imageReference {
c.Fatalf("unexpected Config.Image: %s (expected %s)", res, imageReference) c.Fatalf("unexpected Config.Image: %s (expected %s)", res, imageReference)
} }
} }
func (s *DockerSuite) TestRunByDigest(c *check.C) { func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
defer setupRegistry(c)()
pushDigest, err := setupImage() pushDigest, err := setupImage()
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
@ -181,12 +170,9 @@ func (s *DockerSuite) TestRunByDigest(c *check.C) {
if res != imageReference { if res != imageReference {
c.Fatalf("unexpected Config.Image: %s (expected %s)", res, imageReference) c.Fatalf("unexpected Config.Image: %s (expected %s)", res, imageReference)
} }
} }
func (s *DockerSuite) TestRemoveImageByDigest(c *check.C) { func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
defer setupRegistry(c)()
digest, err := setupImage() digest, err := setupImage()
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
@ -217,12 +203,9 @@ func (s *DockerSuite) TestRemoveImageByDigest(c *check.C) {
} else if !strings.Contains(err.Error(), "No such image") { } else if !strings.Contains(err.Error(), "No such image") {
c.Fatalf("expected 'No such image' output, got %v", err) c.Fatalf("expected 'No such image' output, got %v", err)
} }
} }
func (s *DockerSuite) TestBuildByDigest(c *check.C) { func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
defer setupRegistry(c)()
digest, err := setupImage() digest, err := setupImage()
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
@ -262,12 +245,9 @@ func (s *DockerSuite) TestBuildByDigest(c *check.C) {
if res != imageID { if res != imageID {
c.Fatalf("Image %s, expected %s", res, imageID) c.Fatalf("Image %s, expected %s", res, imageID)
} }
} }
func (s *DockerSuite) TestTagByDigest(c *check.C) { func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
defer setupRegistry(c)()
digest, err := setupImage() digest, err := setupImage()
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
@ -302,12 +282,9 @@ func (s *DockerSuite) TestTagByDigest(c *check.C) {
if tagID != expectedID { if tagID != expectedID {
c.Fatalf("expected image id %q, got %q", expectedID, tagID) c.Fatalf("expected image id %q, got %q", expectedID, tagID)
} }
} }
func (s *DockerSuite) TestListImagesWithoutDigests(c *check.C) { func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
defer setupRegistry(c)()
digest, err := setupImage() digest, err := setupImage()
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
@ -334,8 +311,7 @@ func (s *DockerSuite) TestListImagesWithoutDigests(c *check.C) {
} }
func (s *DockerSuite) TestListImagesWithDigests(c *check.C) { func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
defer setupRegistry(c)()
// setup image1 // setup image1
digest1, err := setupImageWithTag("tag1") digest1, err := setupImageWithTag("tag1")
@ -482,12 +458,9 @@ func (s *DockerSuite) TestListImagesWithDigests(c *check.C) {
if !busyboxRe.MatchString(out) { if !busyboxRe.MatchString(out) {
c.Fatalf("expected %q: %s", busyboxRe.String(), out) c.Fatalf("expected %q: %s", busyboxRe.String(), out)
} }
} }
func (s *DockerSuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) { func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) {
defer setupRegistry(c)()
pushDigest, err := setupImage() pushDigest, err := setupImage()
if err != nil { if err != nil {
c.Fatalf("error setting up image: %v", err) c.Fatalf("error setting up image: %v", err)
@ -511,5 +484,4 @@ func (s *DockerSuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) {
if _, err := runCommand(cmd); err != nil { if _, err := runCommand(cmd); err != nil {
c.Fatalf("error deleting image by id: %v", err) c.Fatalf("error deleting image by id: %v", err)
} }
} }

View file

@ -9,9 +9,7 @@ import (
) )
// See issue docker/docker#8141 // See issue docker/docker#8141
func (s *DockerSuite) TestPullImageWithAliases(c *check.C) { func (s *DockerRegistrySuite) TestPullImageWithAliases(c *check.C) {
defer setupRegistry(c)()
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
repos := []string{} repos := []string{}
@ -48,7 +46,6 @@ func (s *DockerSuite) TestPullImageWithAliases(c *check.C) {
c.Fatalf("Image %v shouldn't have been pulled down", repo) c.Fatalf("Image %v shouldn't have been pulled down", repo)
} }
} }
} }
// pulling library/hello-world should show verified message // pulling library/hello-world should show verified message

View file

@ -13,9 +13,7 @@ import (
) )
// pulling an image from the central registry should work // pulling an image from the central registry should work
func (s *DockerSuite) TestPushBusyboxImage(c *check.C) { func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
defer setupRegistry(c)()
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
// tag the image to upload it to the private registry // tag the image to upload it to the private registry
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName) tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
@ -37,9 +35,7 @@ func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
} }
} }
func (s *DockerSuite) TestPushUntagged(c *check.C) { func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
defer setupRegistry(c)()
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
expected := "Repository does not exist" expected := "Repository does not exist"
@ -51,9 +47,7 @@ func (s *DockerSuite) TestPushUntagged(c *check.C) {
} }
} }
func (s *DockerSuite) TestPushBadTag(c *check.C) { func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
defer setupRegistry(c)()
repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
expected := "does not exist" expected := "does not exist"
@ -65,9 +59,7 @@ func (s *DockerSuite) TestPushBadTag(c *check.C) {
} }
} }
func (s *DockerSuite) TestPushMultipleTags(c *check.C) { func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
defer setupRegistry(c)()
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL) repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL)
repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL) repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
@ -87,8 +79,7 @@ func (s *DockerSuite) TestPushMultipleTags(c *check.C) {
} }
} }
func (s *DockerSuite) TestPushInterrupt(c *check.C) { func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
defer setupRegistry(c)()
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
// tag the image and upload it to the private registry // tag the image and upload it to the private registry
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repoName)); err != nil { if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repoName)); err != nil {
@ -118,8 +109,7 @@ func (s *DockerSuite) TestPushInterrupt(c *check.C) {
} }
} }
func (s *DockerSuite) TestPushEmptyLayer(c *check.C) { func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
defer setupRegistry(c)()
repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL) repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
emptyTarball, err := ioutil.TempFile("", "empty_tarball") emptyTarball, err := ioutil.TempFile("", "empty_tarball")
if err != nil { if err != nil {

View file

@ -1125,7 +1125,7 @@ func daemonTime(c *check.C) time.Time {
return dt return dt
} }
func setupRegistry(c *check.C) func() { func setupRegistry(c *check.C) *testRegistryV2 {
testRequires(c, RegistryHosting) testRequires(c, RegistryHosting)
reg, err := newTestRegistryV2(c) reg, err := newTestRegistryV2(c)
if err != nil { if err != nil {
@ -1143,8 +1143,7 @@ func setupRegistry(c *check.C) func() {
if err != nil { if err != nil {
c.Fatal("Timeout waiting for test registry to become available") c.Fatal("Timeout waiting for test registry to become available")
} }
return reg
return func() { reg.Close() }
} }
// appendBaseEnv appends the minimum set of environment variables to exec the // appendBaseEnv appends the minimum set of environment variables to exec the