github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/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 icmd "github.com/docker/docker/pkg/testutil/cmd" 9 "github.com/go-check/check" 10 ) 11 12 // export an image and try to import it into a new one 13 func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) { 14 testRequires(c, DaemonIsLinux) 15 containerID := "testexportcontainerandimportimage" 16 17 dockerCmd(c, "run", "--name", containerID, "busybox", "true") 18 19 out, _ := dockerCmd(c, "export", containerID) 20 21 result := icmd.RunCmd(icmd.Cmd{ 22 Command: []string{dockerBinary, "import", "-", "repo/testexp:v1"}, 23 Stdin: strings.NewReader(out), 24 }) 25 result.Assert(c, icmd.Success) 26 27 cleanedImageID := strings.TrimSpace(result.Combined()) 28 c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id")) 29 } 30 31 // Used to test output flag in the export command 32 func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) { 33 testRequires(c, DaemonIsLinux) 34 containerID := "testexportcontainerwithoutputandimportimage" 35 36 dockerCmd(c, "run", "--name", containerID, "busybox", "true") 37 dockerCmd(c, "export", "--output=testexp.tar", containerID) 38 defer os.Remove("testexp.tar") 39 40 resultCat := icmd.RunCommand("cat", "testexp.tar") 41 resultCat.Assert(c, icmd.Success) 42 43 result := icmd.RunCmd(icmd.Cmd{ 44 Command: []string{dockerBinary, "import", "-", "repo/testexp:v1"}, 45 Stdin: strings.NewReader(resultCat.Combined()), 46 }) 47 result.Assert(c, icmd.Success) 48 49 cleanedImageID := strings.TrimSpace(result.Combined()) 50 c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id")) 51 }