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