github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/integration-cli/docker_cli_export_import_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"strings"
     6  
     7  	"github.com/docker/docker/integration-cli/checker"
     8  	"github.com/go-check/check"
     9  	"gotest.tools/icmd"
    10  )
    11  
    12  // TODO: Move this test to docker/cli, as it is essentially the same test
    13  // as TestExportContainerAndImportImage except output to a file.
    14  // Used to test output flag in the export command
    15  func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
    16  	testRequires(c, DaemonIsLinux)
    17  	containerID := "testexportcontainerwithoutputandimportimage"
    18  
    19  	dockerCmd(c, "run", "--name", containerID, "busybox", "true")
    20  	dockerCmd(c, "export", "--output=testexp.tar", containerID)
    21  	defer os.Remove("testexp.tar")
    22  
    23  	resultCat := icmd.RunCommand("cat", "testexp.tar")
    24  	resultCat.Assert(c, icmd.Success)
    25  
    26  	result := icmd.RunCmd(icmd.Cmd{
    27  		Command: []string{dockerBinary, "import", "-", "repo/testexp:v1"},
    28  		Stdin:   strings.NewReader(resultCat.Combined()),
    29  	})
    30  	result.Assert(c, icmd.Success)
    31  
    32  	cleanedImageID := strings.TrimSpace(result.Combined())
    33  	c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
    34  }