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