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

     1  package container
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/docker/cli/e2e/internal/fixtures"
     8  	"github.com/docker/cli/internal/test/environment"
     9  	"gotest.tools/assert"
    10  	is "gotest.tools/assert/cmp"
    11  	"gotest.tools/golden"
    12  	"gotest.tools/icmd"
    13  	"gotest.tools/skip"
    14  )
    15  
    16  const registryPrefix = "registry:5000"
    17  
    18  func TestRunAttachedFromRemoteImageAndRemove(t *testing.T) {
    19  	skip.If(t, environment.RemoteDaemon())
    20  
    21  	image := createRemoteImage(t)
    22  
    23  	result := icmd.RunCommand("docker", "run", "--rm", image,
    24  		"echo", "this", "is", "output")
    25  
    26  	result.Assert(t, icmd.Success)
    27  	assert.Check(t, is.Equal("this is output\n", result.Stdout()))
    28  	golden.Assert(t, result.Stderr(), "run-attached-from-remote-and-remove.golden")
    29  }
    30  
    31  func TestRunWithContentTrust(t *testing.T) {
    32  	skip.If(t, environment.RemoteDaemon())
    33  
    34  	dir := fixtures.SetupConfigFile(t)
    35  	defer dir.Remove()
    36  	image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-run", "latest")
    37  
    38  	defer func() {
    39  		icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
    40  	}()
    41  
    42  	result := icmd.RunCmd(
    43  		icmd.Command("docker", "run", image),
    44  		fixtures.WithConfig(dir.Path()),
    45  		fixtures.WithTrust,
    46  		fixtures.WithNotary,
    47  	)
    48  	result.Assert(t, icmd.Expected{
    49  		Err: fmt.Sprintf("Tagging %s@sha", image[:len(image)-7]),
    50  	})
    51  }
    52  
    53  // TODO: create this with registry API instead of engine API
    54  func createRemoteImage(t *testing.T) string {
    55  	image := "registry:5000/alpine:test-run-pulls"
    56  	icmd.RunCommand("docker", "pull", fixtures.AlpineImage).Assert(t, icmd.Success)
    57  	icmd.RunCommand("docker", "tag", fixtures.AlpineImage, image).Assert(t, icmd.Success)
    58  	icmd.RunCommand("docker", "push", image).Assert(t, icmd.Success)
    59  	icmd.RunCommand("docker", "rmi", image).Assert(t, icmd.Success)
    60  	return image
    61  }