github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/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  
     9  	"github.com/docker/docker/internal/test/registry"
    10  	"github.com/go-check/check"
    11  )
    12  
    13  func makefile(path string, contents string) (string, error) {
    14  	f, err := ioutil.TempFile(path, "tmp")
    15  	if err != nil {
    16  		return "", err
    17  	}
    18  	err = ioutil.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 *check.C) {
    28  	reg, err := registry.NewMock(c)
    29  	defer reg.Close()
    30  	c.Assert(err, check.IsNil)
    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 := ioutil.TempDir("", "integration-cli-")
    45  	c.Assert(err, check.IsNil)
    46  	defer os.RemoveAll(tmp)
    47  
    48  	dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s/busybox", reg.URL()))
    49  	c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
    50  
    51  	s.d.Cmd("build", "--file", dockerfileName, tmp)
    52  
    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  }