docker_cli_v2_only_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "net/http"
  6. "os"
  7. "github.com/docker/docker/integration-cli/registry"
  8. "github.com/go-check/check"
  9. )
  10. func makefile(path string, contents string) (string, error) {
  11. f, err := ioutil.TempFile(path, "tmp")
  12. if err != nil {
  13. return "", err
  14. }
  15. err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm)
  16. if err != nil {
  17. return "", err
  18. }
  19. return f.Name(), nil
  20. }
  21. // TestV2Only ensures that a daemon does not
  22. // attempt to contact any v1 registry endpoints.
  23. func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
  24. reg, err := registry.NewMock(c)
  25. defer reg.Close()
  26. c.Assert(err, check.IsNil)
  27. reg.RegisterHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
  28. w.WriteHeader(404)
  29. })
  30. reg.RegisterHandler("/v1/.*", func(w http.ResponseWriter, r *http.Request) {
  31. c.Fatal("V1 registry contacted")
  32. })
  33. repoName := fmt.Sprintf("%s/busybox", reg.URL())
  34. s.d.Start(c, "--insecure-registry", reg.URL())
  35. tmp, err := ioutil.TempDir("", "integration-cli-")
  36. c.Assert(err, check.IsNil)
  37. defer os.RemoveAll(tmp)
  38. dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s/busybox", reg.URL()))
  39. c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
  40. s.d.Cmd("build", "--file", dockerfileName, tmp)
  41. s.d.Cmd("run", repoName)
  42. s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
  43. s.d.Cmd("tag", "busybox", repoName)
  44. s.d.Cmd("push", repoName)
  45. s.d.Cmd("pull", repoName)
  46. }