use of checkers on docker_cli_v2_only.go

Signed-off-by: weiyan <weiyan3@huawei.com>
This commit is contained in:
weiyan 2015-10-14 20:10:34 +08:00
parent 7a19164c17
commit 899ca94ce8

View file

@ -37,9 +37,7 @@ func makefile(contents string) (string, func(), error) {
// attempt to contact any v1 registry endpoints.
func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
reg, err := newTestRegistry(c)
if err != nil {
c.Fatal(err.Error())
}
c.Assert(err, check.IsNil)
reg.registerHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
@ -52,14 +50,10 @@ func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
repoName := fmt.Sprintf("%s/busybox", reg.hostport)
err = s.d.Start("--insecure-registry", reg.hostport, "--disable-legacy-registry=true")
if err != nil {
c.Fatalf("Error starting daemon: %s", err.Error())
}
c.Assert(err, check.IsNil)
dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.hostport))
if err != nil {
c.Fatalf("Unable to create test dockerfile")
}
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
defer cleanup()
s.d.Cmd("build", "--file", dockerfileName, ".")
@ -76,9 +70,7 @@ func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
// login, push, pull, build & run
func (s *DockerRegistrySuite) TestV1(c *check.C) {
reg, err := newTestRegistry(c)
if err != nil {
c.Fatal(err.Error())
}
c.Assert(err, check.IsNil)
v2Pings := 0
reg.registerHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
@ -107,42 +99,29 @@ func (s *DockerRegistrySuite) TestV1(c *check.C) {
})
err = s.d.Start("--insecure-registry", reg.hostport, "--disable-legacy-registry=false")
if err != nil {
c.Fatalf("Error starting daemon: %s", err.Error())
}
c.Assert(err, check.IsNil)
dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.hostport))
if err != nil {
c.Fatalf("Unable to create test dockerfile")
}
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
defer cleanup()
s.d.Cmd("build", "--file", dockerfileName, ".")
if v1Repo == 0 {
c.Errorf("Expected v1 repository access after build")
}
c.Assert(v1Repo, check.Not(check.Equals), 0, check.Commentf("Expected v1 repository access after build"))
repoName := fmt.Sprintf("%s/busybox", reg.hostport)
s.d.Cmd("run", repoName)
if v1Repo == 1 {
c.Errorf("Expected v1 repository access after run")
}
c.Assert(v1Repo, check.Not(check.Equals), 1, check.Commentf("Expected v1 repository access after run"))
s.d.Cmd("login", "-u", "richard", "-p", "testtest", "-e", "testuser@testdomain.com", reg.hostport)
if v1Logins == 0 {
c.Errorf("Expected v1 login attempt")
}
c.Assert(v1Logins, check.Not(check.Equals), 0, check.Commentf("Expected v1 login attempt"))
s.d.Cmd("tag", "busybox", repoName)
s.d.Cmd("push", repoName)
if v1Repo != 2 || v1Pings != 1 {
c.Error("Not all endpoints contacted after push", v1Repo, v1Pings)
}
c.Assert(v1Repo, check.Equals, 2)
c.Assert(v1Pings, check.Equals, 1)
s.d.Cmd("pull", repoName)
if v1Repo != 3 {
c.Errorf("Expected v1 repository access after pull")
}
c.Assert(v1Repo, check.Equals, 3, check.Commentf("Expected v1 repository access after pull"))
}