github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/e2e/image/pull_test.go (about)

     1  package image
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/khulnasoft/cli/e2e/internal/fixtures"
     7  	"github.com/khulnasoft/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  	// Digests in golden files are linux/amd64 specific.
    21  	// TODO: Fix this test and make it work on all platforms.
    22  	environment.SkipIfNotPlatform(t, "linux/amd64")
    23  
    24  	dir := fixtures.SetupConfigFile(t)
    25  	defer dir.Remove()
    26  	image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-pull", "latest")
    27  	defer func() {
    28  		icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
    29  	}()
    30  
    31  	result := icmd.RunCmd(icmd.Command("docker", "pull", image),
    32  		fixtures.WithConfig(dir.Path()),
    33  		fixtures.WithTrust,
    34  		fixtures.WithNotary,
    35  	)
    36  	result.Assert(t, icmd.Success)
    37  	golden.Assert(t, result.Stderr(), "pull-with-content-trust-err.golden")
    38  	golden.Assert(t, result.Stdout(), "pull-with-content-trust.golden")
    39  }
    40  
    41  func TestPullQuiet(t *testing.T) {
    42  	result := icmd.RunCommand("docker", "pull", "--quiet", fixtures.AlpineImage)
    43  	result.Assert(t, icmd.Success)
    44  	assert.Check(t, is.Equal(result.Stdout(), "registry:5000/alpine:frozen\n"))
    45  	assert.Check(t, is.Equal(result.Stderr(), ""))
    46  }
    47  
    48  func TestPullWithContentTrustUsesCacheWhenNotaryUnavailable(t *testing.T) {
    49  	skip.If(t, environment.RemoteDaemon())
    50  
    51  	dir := fixtures.SetupConfigFile(t)
    52  	defer dir.Remove()
    53  	image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-pull-unreachable", "latest")
    54  	defer func() {
    55  		icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
    56  	}()
    57  	result := icmd.RunCmd(icmd.Command("docker", "pull", image),
    58  		fixtures.WithConfig(dir.Path()),
    59  		fixtures.WithTrust,
    60  		fixtures.WithNotaryServer("https://invalidnotaryserver"),
    61  	)
    62  	result.Assert(t, icmd.Expected{
    63  		ExitCode: 1,
    64  		Err:      "error contacting notary server",
    65  	})
    66  
    67  	// Do valid trusted pull to warm cache
    68  	result = icmd.RunCmd(icmd.Command("docker", "pull", image),
    69  		fixtures.WithConfig(dir.Path()),
    70  		fixtures.WithTrust,
    71  		fixtures.WithNotary,
    72  	)
    73  	result.Assert(t, icmd.Success)
    74  	result = icmd.RunCommand("docker", "rmi", image)
    75  	result.Assert(t, icmd.Success)
    76  
    77  	// Try pull again with invalid notary server, should use cache
    78  	result = icmd.RunCmd(icmd.Command("docker", "pull", image),
    79  		fixtures.WithConfig(dir.Path()),
    80  		fixtures.WithTrust,
    81  		fixtures.WithNotaryServer("https://invalidnotaryserver"),
    82  	)
    83  	result.Assert(t, icmd.Success)
    84  }