github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/e2e/image/pull_test.go (about)

     1  package image
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/cli/e2e/internal/fixtures"
     7  	"github.com/docker/cli/internal/test/environment"
     8  	"gotest.tools/golden"
     9  	"gotest.tools/icmd"
    10  	"gotest.tools/skip"
    11  )
    12  
    13  const registryPrefix = "registry:5000"
    14  
    15  func TestPullWithContentTrust(t *testing.T) {
    16  	skip.If(t, environment.RemoteDaemon())
    17  
    18  	dir := fixtures.SetupConfigFile(t)
    19  	defer dir.Remove()
    20  	image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-pull", "latest")
    21  	defer func() {
    22  		icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
    23  	}()
    24  
    25  	result := icmd.RunCmd(icmd.Command("docker", "pull", image),
    26  		fixtures.WithConfig(dir.Path()),
    27  		fixtures.WithTrust,
    28  		fixtures.WithNotary,
    29  	)
    30  	result.Assert(t, icmd.Success)
    31  	golden.Assert(t, result.Stderr(), "pull-with-content-trust-err.golden")
    32  	golden.Assert(t, result.Stdout(), "pull-with-content-trust.golden")
    33  }
    34  
    35  func TestPullWithContentTrustUsesCacheWhenNotaryUnavailable(t *testing.T) {
    36  	skip.If(t, environment.RemoteDaemon())
    37  
    38  	dir := fixtures.SetupConfigFile(t)
    39  	defer dir.Remove()
    40  	image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-pull-unreachable", "latest")
    41  	defer func() {
    42  		icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
    43  	}()
    44  	result := icmd.RunCmd(icmd.Command("docker", "pull", image),
    45  		fixtures.WithConfig(dir.Path()),
    46  		fixtures.WithTrust,
    47  		fixtures.WithNotaryServer("https://invalidnotaryserver"),
    48  	)
    49  	result.Assert(t, icmd.Expected{
    50  		ExitCode: 1,
    51  		Err:      "error contacting notary server",
    52  	})
    53  
    54  	// Do valid trusted pull to warm cache
    55  	result = icmd.RunCmd(icmd.Command("docker", "pull", image),
    56  		fixtures.WithConfig(dir.Path()),
    57  		fixtures.WithTrust,
    58  		fixtures.WithNotary,
    59  	)
    60  	result.Assert(t, icmd.Success)
    61  	result = icmd.RunCommand("docker", "rmi", image)
    62  	result.Assert(t, icmd.Success)
    63  
    64  	// Try pull again with invalid notary server, should use cache
    65  	result = icmd.RunCmd(icmd.Command("docker", "pull", image),
    66  		fixtures.WithConfig(dir.Path()),
    67  		fixtures.WithTrust,
    68  		fixtures.WithNotaryServer("https://invalidnotaryserver"),
    69  	)
    70  	result.Assert(t, icmd.Success)
    71  }