Signed-off-by: Antonio Murdaca <runcom@redhat.com>
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,127 +0,0 @@ |
| 1 |
-package main |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "fmt" |
|
| 5 |
- "io/ioutil" |
|
| 6 |
- "net/http" |
|
| 7 |
- "os" |
|
| 8 |
- |
|
| 9 |
- "github.com/go-check/check" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-func makefile(contents string) (string, func(), error) {
|
|
| 13 |
- cleanup := func() {
|
|
| 14 |
- |
|
| 15 |
- } |
|
| 16 |
- |
|
| 17 |
- f, err := ioutil.TempFile(".", "tmp")
|
|
| 18 |
- if err != nil {
|
|
| 19 |
- return "", cleanup, err |
|
| 20 |
- } |
|
| 21 |
- err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm) |
|
| 22 |
- if err != nil {
|
|
| 23 |
- return "", cleanup, err |
|
| 24 |
- } |
|
| 25 |
- |
|
| 26 |
- cleanup = func() {
|
|
| 27 |
- err := os.Remove(f.Name()) |
|
| 28 |
- if err != nil {
|
|
| 29 |
- fmt.Println("Error removing tmpfile")
|
|
| 30 |
- } |
|
| 31 |
- } |
|
| 32 |
- return f.Name(), cleanup, nil |
|
| 33 |
- |
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-// TestV2Only ensures that a daemon in v2-only mode does not |
|
| 37 |
-// attempt to contact any v1 registry endpoints. |
|
| 38 |
-func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
|
|
| 39 |
- reg, err := newTestRegistry(c) |
|
| 40 |
- c.Assert(err, check.IsNil) |
|
| 41 |
- |
|
| 42 |
- reg.registerHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
|
|
| 43 |
- w.WriteHeader(404) |
|
| 44 |
- }) |
|
| 45 |
- |
|
| 46 |
- reg.registerHandler("/v1/.*", func(w http.ResponseWriter, r *http.Request) {
|
|
| 47 |
- c.Fatal("V1 registry contacted")
|
|
| 48 |
- }) |
|
| 49 |
- |
|
| 50 |
- repoName := fmt.Sprintf("%s/busybox", reg.hostport)
|
|
| 51 |
- |
|
| 52 |
- err = s.d.Start("--insecure-registry", reg.hostport, "--disable-legacy-registry=true")
|
|
| 53 |
- c.Assert(err, check.IsNil) |
|
| 54 |
- |
|
| 55 |
- dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.hostport))
|
|
| 56 |
- c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
|
| 57 |
- defer cleanup() |
|
| 58 |
- |
|
| 59 |
- s.d.Cmd("build", "--file", dockerfileName, ".")
|
|
| 60 |
- |
|
| 61 |
- s.d.Cmd("run", repoName)
|
|
| 62 |
- s.d.Cmd("login", "-u", "richard", "-p", "testtest", "-e", "testuser@testdomain.com", reg.hostport)
|
|
| 63 |
- s.d.Cmd("tag", "busybox", repoName)
|
|
| 64 |
- s.d.Cmd("push", repoName)
|
|
| 65 |
- s.d.Cmd("pull", repoName)
|
|
| 66 |
-} |
|
| 67 |
- |
|
| 68 |
-// TestV1 starts a daemon in 'normal' mode |
|
| 69 |
-// and ensure v1 endpoints are hit for the following operations: |
|
| 70 |
-// login, push, pull, build & run |
|
| 71 |
-func (s *DockerRegistrySuite) TestV1(c *check.C) {
|
|
| 72 |
- reg, err := newTestRegistry(c) |
|
| 73 |
- c.Assert(err, check.IsNil) |
|
| 74 |
- |
|
| 75 |
- v2Pings := 0 |
|
| 76 |
- reg.registerHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
|
|
| 77 |
- v2Pings++ |
|
| 78 |
- // V2 ping 404 causes fallback to v1 |
|
| 79 |
- w.WriteHeader(404) |
|
| 80 |
- }) |
|
| 81 |
- |
|
| 82 |
- v1Pings := 0 |
|
| 83 |
- reg.registerHandler("/v1/_ping", func(w http.ResponseWriter, r *http.Request) {
|
|
| 84 |
- v1Pings++ |
|
| 85 |
- }) |
|
| 86 |
- |
|
| 87 |
- v1Logins := 0 |
|
| 88 |
- reg.registerHandler("/v1/users/", func(w http.ResponseWriter, r *http.Request) {
|
|
| 89 |
- v1Logins++ |
|
| 90 |
- }) |
|
| 91 |
- |
|
| 92 |
- v1Repo := 0 |
|
| 93 |
- reg.registerHandler("/v1/repositories/busybox/", func(w http.ResponseWriter, r *http.Request) {
|
|
| 94 |
- v1Repo++ |
|
| 95 |
- }) |
|
| 96 |
- |
|
| 97 |
- reg.registerHandler("/v1/repositories/busybox/images", func(w http.ResponseWriter, r *http.Request) {
|
|
| 98 |
- v1Repo++ |
|
| 99 |
- }) |
|
| 100 |
- |
|
| 101 |
- err = s.d.Start("--insecure-registry", reg.hostport, "--disable-legacy-registry=false")
|
|
| 102 |
- c.Assert(err, check.IsNil) |
|
| 103 |
- |
|
| 104 |
- dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.hostport))
|
|
| 105 |
- c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
|
| 106 |
- defer cleanup() |
|
| 107 |
- |
|
| 108 |
- s.d.Cmd("build", "--file", dockerfileName, ".")
|
|
| 109 |
- c.Assert(v1Repo, check.Not(check.Equals), 0, check.Commentf("Expected v1 repository access after build"))
|
|
| 110 |
- |
|
| 111 |
- repoName := fmt.Sprintf("%s/busybox", reg.hostport)
|
|
| 112 |
- s.d.Cmd("run", repoName)
|
|
| 113 |
- c.Assert(v1Repo, check.Not(check.Equals), 1, check.Commentf("Expected v1 repository access after run"))
|
|
| 114 |
- |
|
| 115 |
- s.d.Cmd("login", "-u", "richard", "-p", "testtest", "-e", "testuser@testdomain.com", reg.hostport)
|
|
| 116 |
- c.Assert(v1Logins, check.Not(check.Equals), 0, check.Commentf("Expected v1 login attempt"))
|
|
| 117 |
- |
|
| 118 |
- s.d.Cmd("tag", "busybox", repoName)
|
|
| 119 |
- s.d.Cmd("push", repoName)
|
|
| 120 |
- |
|
| 121 |
- c.Assert(v1Repo, check.Equals, 2) |
|
| 122 |
- c.Assert(v1Pings, check.Equals, 1) |
|
| 123 |
- |
|
| 124 |
- s.d.Cmd("pull", repoName)
|
|
| 125 |
- c.Assert(v1Repo, check.Equals, 3, check.Commentf("Expected v1 repository access after pull"))
|
|
| 126 |
- |
|
| 127 |
-} |
| 128 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,126 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "io/ioutil" |
|
| 5 |
+ "net/http" |
|
| 6 |
+ "os" |
|
| 7 |
+ |
|
| 8 |
+ "github.com/go-check/check" |
|
| 9 |
+) |
|
| 10 |
+ |
|
| 11 |
+func makefile(contents string) (string, func(), error) {
|
|
| 12 |
+ cleanup := func() {
|
|
| 13 |
+ |
|
| 14 |
+ } |
|
| 15 |
+ |
|
| 16 |
+ f, err := ioutil.TempFile(".", "tmp")
|
|
| 17 |
+ if err != nil {
|
|
| 18 |
+ return "", cleanup, err |
|
| 19 |
+ } |
|
| 20 |
+ err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm) |
|
| 21 |
+ if err != nil {
|
|
| 22 |
+ return "", cleanup, err |
|
| 23 |
+ } |
|
| 24 |
+ |
|
| 25 |
+ cleanup = func() {
|
|
| 26 |
+ err := os.Remove(f.Name()) |
|
| 27 |
+ if err != nil {
|
|
| 28 |
+ fmt.Println("Error removing tmpfile")
|
|
| 29 |
+ } |
|
| 30 |
+ } |
|
| 31 |
+ return f.Name(), cleanup, nil |
|
| 32 |
+ |
|
| 33 |
+} |
|
| 34 |
+ |
|
| 35 |
+// TestV2Only ensures that a daemon in v2-only mode does not |
|
| 36 |
+// attempt to contact any v1 registry endpoints. |
|
| 37 |
+func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
|
|
| 38 |
+ reg, err := newTestRegistry(c) |
|
| 39 |
+ c.Assert(err, check.IsNil) |
|
| 40 |
+ |
|
| 41 |
+ reg.registerHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
|
|
| 42 |
+ w.WriteHeader(404) |
|
| 43 |
+ }) |
|
| 44 |
+ |
|
| 45 |
+ reg.registerHandler("/v1/.*", func(w http.ResponseWriter, r *http.Request) {
|
|
| 46 |
+ c.Fatal("V1 registry contacted")
|
|
| 47 |
+ }) |
|
| 48 |
+ |
|
| 49 |
+ repoName := fmt.Sprintf("%s/busybox", reg.hostport)
|
|
| 50 |
+ |
|
| 51 |
+ err = s.d.Start("--insecure-registry", reg.hostport, "--disable-legacy-registry=true")
|
|
| 52 |
+ c.Assert(err, check.IsNil) |
|
| 53 |
+ |
|
| 54 |
+ dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.hostport))
|
|
| 55 |
+ c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
|
| 56 |
+ defer cleanup() |
|
| 57 |
+ |
|
| 58 |
+ s.d.Cmd("build", "--file", dockerfileName, ".")
|
|
| 59 |
+ |
|
| 60 |
+ s.d.Cmd("run", repoName)
|
|
| 61 |
+ s.d.Cmd("login", "-u", "richard", "-p", "testtest", "-e", "testuser@testdomain.com", reg.hostport)
|
|
| 62 |
+ s.d.Cmd("tag", "busybox", repoName)
|
|
| 63 |
+ s.d.Cmd("push", repoName)
|
|
| 64 |
+ s.d.Cmd("pull", repoName)
|
|
| 65 |
+} |
|
| 66 |
+ |
|
| 67 |
+// TestV1 starts a daemon in 'normal' mode |
|
| 68 |
+// and ensure v1 endpoints are hit for the following operations: |
|
| 69 |
+// login, push, pull, build & run |
|
| 70 |
+func (s *DockerRegistrySuite) TestV1(c *check.C) {
|
|
| 71 |
+ reg, err := newTestRegistry(c) |
|
| 72 |
+ c.Assert(err, check.IsNil) |
|
| 73 |
+ |
|
| 74 |
+ v2Pings := 0 |
|
| 75 |
+ reg.registerHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
|
|
| 76 |
+ v2Pings++ |
|
| 77 |
+ // V2 ping 404 causes fallback to v1 |
|
| 78 |
+ w.WriteHeader(404) |
|
| 79 |
+ }) |
|
| 80 |
+ |
|
| 81 |
+ v1Pings := 0 |
|
| 82 |
+ reg.registerHandler("/v1/_ping", func(w http.ResponseWriter, r *http.Request) {
|
|
| 83 |
+ v1Pings++ |
|
| 84 |
+ }) |
|
| 85 |
+ |
|
| 86 |
+ v1Logins := 0 |
|
| 87 |
+ reg.registerHandler("/v1/users/", func(w http.ResponseWriter, r *http.Request) {
|
|
| 88 |
+ v1Logins++ |
|
| 89 |
+ }) |
|
| 90 |
+ |
|
| 91 |
+ v1Repo := 0 |
|
| 92 |
+ reg.registerHandler("/v1/repositories/busybox/", func(w http.ResponseWriter, r *http.Request) {
|
|
| 93 |
+ v1Repo++ |
|
| 94 |
+ }) |
|
| 95 |
+ |
|
| 96 |
+ reg.registerHandler("/v1/repositories/busybox/images", func(w http.ResponseWriter, r *http.Request) {
|
|
| 97 |
+ v1Repo++ |
|
| 98 |
+ }) |
|
| 99 |
+ |
|
| 100 |
+ err = s.d.Start("--insecure-registry", reg.hostport, "--disable-legacy-registry=false")
|
|
| 101 |
+ c.Assert(err, check.IsNil) |
|
| 102 |
+ |
|
| 103 |
+ dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.hostport))
|
|
| 104 |
+ c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
|
| 105 |
+ defer cleanup() |
|
| 106 |
+ |
|
| 107 |
+ s.d.Cmd("build", "--file", dockerfileName, ".")
|
|
| 108 |
+ c.Assert(v1Repo, check.Not(check.Equals), 0, check.Commentf("Expected v1 repository access after build"))
|
|
| 109 |
+ |
|
| 110 |
+ repoName := fmt.Sprintf("%s/busybox", reg.hostport)
|
|
| 111 |
+ s.d.Cmd("run", repoName)
|
|
| 112 |
+ c.Assert(v1Repo, check.Not(check.Equals), 1, check.Commentf("Expected v1 repository access after run"))
|
|
| 113 |
+ |
|
| 114 |
+ s.d.Cmd("login", "-u", "richard", "-p", "testtest", "-e", "testuser@testdomain.com", reg.hostport)
|
|
| 115 |
+ c.Assert(v1Logins, check.Not(check.Equals), 0, check.Commentf("Expected v1 login attempt"))
|
|
| 116 |
+ |
|
| 117 |
+ s.d.Cmd("tag", "busybox", repoName)
|
|
| 118 |
+ s.d.Cmd("push", repoName)
|
|
| 119 |
+ |
|
| 120 |
+ c.Assert(v1Repo, check.Equals, 2) |
|
| 121 |
+ c.Assert(v1Pings, check.Equals, 1) |
|
| 122 |
+ |
|
| 123 |
+ s.d.Cmd("pull", repoName)
|
|
| 124 |
+ c.Assert(v1Repo, check.Equals, 3, check.Commentf("Expected v1 repository access after pull"))
|
|
| 125 |
+} |