github.com/docker/docker-ce@v17.12.1-ce-rc2+incompatible/components/cli/e2e/internal/fixtures/fixtures.go (about)

     1  package fixtures
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/gotestyourself/gotestyourself/fs"
     8  	"github.com/gotestyourself/gotestyourself/icmd"
     9  )
    10  
    11  const (
    12  	//NotaryURL is the location of the notary server
    13  	NotaryURL = "https://notary-server:4443"
    14  	//AlpineImage is an image in the test registry
    15  	AlpineImage = "registry:5000/alpine:3.6"
    16  	//AlpineSha is the sha of the alpine image
    17  	AlpineSha = "641b95ddb2ea9dc2af1a0113b6b348ebc20872ba615204fbe12148e98fd6f23d"
    18  	//BusyboxImage is an image in the test registry
    19  	BusyboxImage = "registry:5000/busybox:1.27.2"
    20  	//BusyboxSha is the sha of the busybox image
    21  	BusyboxSha = "030fcb92e1487b18c974784dcc110a93147c9fc402188370fbfd17efabffc6af"
    22  )
    23  
    24  //SetupConfigFile creates a config.json file for testing
    25  func SetupConfigFile(t *testing.T) fs.Dir {
    26  	dir := fs.NewDir(t, "trust_test", fs.WithMode(0700), fs.WithFile("config.json", `
    27  	{
    28  		"auths": {
    29  			"registry:5000": {
    30  				"auth": "ZWlhaXM6cGFzc3dvcmQK"
    31  			},
    32  			"https://notary-server:4443": {
    33  				"auth": "ZWlhaXM6cGFzc3dvcmQK"
    34  			}
    35  		}
    36  	}
    37  	`))
    38  	return *dir
    39  }
    40  
    41  //WithConfig sets an environment variable for the docker config location
    42  func WithConfig(dir string) func(cmd *icmd.Cmd) {
    43  	return func(cmd *icmd.Cmd) {
    44  		env := append(os.Environ(),
    45  			"DOCKER_CONFIG="+dir,
    46  		)
    47  		cmd.Env = append(cmd.Env, env...)
    48  	}
    49  }
    50  
    51  //WithPassphrase sets environment variables for passphrases
    52  func WithPassphrase(rootPwd, repositoryPwd string) func(cmd *icmd.Cmd) {
    53  	return func(cmd *icmd.Cmd) {
    54  		env := append(os.Environ(),
    55  			"DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE="+rootPwd,
    56  			"DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE="+repositoryPwd,
    57  		)
    58  		cmd.Env = append(cmd.Env, env...)
    59  	}
    60  }
    61  
    62  //WithTrust sets DOCKER_CONTENT_TRUST to 1
    63  func WithTrust(cmd *icmd.Cmd) {
    64  	env := append(os.Environ(),
    65  		"DOCKER_CONTENT_TRUST=1",
    66  	)
    67  	cmd.Env = append(cmd.Env, env...)
    68  }
    69  
    70  //WithNotary sets the location of the notary server
    71  func WithNotary(cmd *icmd.Cmd) {
    72  	env := append(os.Environ(),
    73  		"DOCKER_CONTENT_TRUST_SERVER="+NotaryURL,
    74  	)
    75  	cmd.Env = append(cmd.Env, env...)
    76  }