github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/cli/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/v3/assert"
     9  	is "gotest.tools/v3/assert/cmp"
    10  	"gotest.tools/v3/golden"
    11  	"gotest.tools/v3/icmd"
    12  	"gotest.tools/v3/skip"
    13  )
    14  
    15  const registryPrefix = "registry:5000"
    16  
    17  func TestPullWithContentTrust(t *testing.T) {
    18  	skip.If(t, environment.RemoteDaemon())
    19  
    20  	dir := fixtures.SetupConfigFile(t)
    21  	defer dir.Remove()
    22  	image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-pull", "latest")
    23  	defer func() {
    24  		icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
    25  	}()
    26  
    27  	result := icmd.RunCmd(icmd.Command("docker", "pull", image),
    28  		fixtures.WithConfig(dir.Path()),
    29  		fixtures.WithTrust,
    30  		fixtures.WithNotary,
    31  	)
    32  	result.Assert(t, icmd.Success)
    33  	golden.Assert(t, result.Stderr(), "pull-with-content-trust-err.golden")
    34  	golden.Assert(t, result.Stdout(), "pull-with-content-trust.golden")
    35  }
    36  
    37  func TestPullQuiet(t *testing.T) {
    38  	result := icmd.RunCommand("docker", "pull", "--quiet", fixtures.AlpineImage)
    39  	result.Assert(t, icmd.Success)
    40  	assert.Check(t, is.Equal(result.Stdout(), "registry:5000/alpine:3.6\n"))
    41  	assert.Check(t, is.Equal(result.Stderr(), ""))
    42  }
    43  
    44  func TestPullWithContentTrustUsesCacheWhenNotaryUnavailable(t *testing.T) {
    45  	skip.If(t, environment.RemoteDaemon())
    46  
    47  	dir := fixtures.SetupConfigFile(t)
    48  	defer dir.Remove()
    49  	image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-pull-unreachable", "latest")
    50  	defer func() {
    51  		icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
    52  	}()
    53  	result := icmd.RunCmd(icmd.Command("docker", "pull", image),
    54  		fixtures.WithConfig(dir.Path()),
    55  		fixtures.WithTrust,
    56  		fixtures.WithNotaryServer("https://invalidnotaryserver"),
    57  	)
    58  	result.Assert(t, icmd.Expected{
    59  		ExitCode: 1,
    60  		Err:      "error contacting notary server",
    61  	})
    62  
    63  	// Do valid trusted pull to warm cache
    64  	result = icmd.RunCmd(icmd.Command("docker", "pull", image),
    65  		fixtures.WithConfig(dir.Path()),
    66  		fixtures.WithTrust,
    67  		fixtures.WithNotary,
    68  	)
    69  	result.Assert(t, icmd.Success)
    70  	result = icmd.RunCommand("docker", "rmi", image)
    71  	result.Assert(t, icmd.Success)
    72  
    73  	// Try pull again with invalid notary server, should use cache
    74  	result = icmd.RunCmd(icmd.Command("docker", "pull", image),
    75  		fixtures.WithConfig(dir.Path()),
    76  		fixtures.WithTrust,
    77  		fixtures.WithNotaryServer("https://invalidnotaryserver"),
    78  	)
    79  	result.Assert(t, icmd.Success)
    80  }