integration-cli/docker_cli_export_import_test.go
6db32fde
 package main
 
 import (
5ff122f7
 	"os"
6db32fde
 	"os/exec"
48d87577
 	"strings"
dc944ea7
 
 	"github.com/go-check/check"
6db32fde
 )
 
 // export an image and try to import it into a new one
dc944ea7
 func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
4e356ee4
 	containerID := "testexportcontainerandimportimage"
 
668e2369
 	dockerCmd(c, "run", "--name", containerID, "busybox", "true")
6db32fde
 
668e2369
 	out, _ := dockerCmd(c, "export", containerID)
6db32fde
 
48d87577
 	importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
 	importCmd.Stdin = strings.NewReader(out)
668e2369
 	out, _, err := runCommandWithOutput(importCmd)
b645df1d
 	if err != nil {
dc944ea7
 		c.Fatalf("failed to import image: %s, %v", out, err)
b645df1d
 	}
6db32fde
 
475c6531
 	cleanedImageID := strings.TrimSpace(out)
a268e367
 	if cleanedImageID == "" {
 		c.Fatalf("output should have been an image id, got: %s", out)
b645df1d
 	}
6db32fde
 }
5ff122f7
 
 // Used to test output flag in the export command
dc944ea7
 func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
4e356ee4
 	containerID := "testexportcontainerwithoutputandimportimage"
 
668e2369
 	dockerCmd(c, "run", "--name", containerID, "busybox", "true")
 	dockerCmd(c, "export", "--output=testexp.tar", containerID)
4e356ee4
 	defer os.Remove("testexp.tar")
 
668e2369
 	out, _, err := runCommandWithOutput(exec.Command("cat", "testexp.tar"))
6a313e81
 	if err != nil {
dc944ea7
 		c.Fatal(out, err)
6a313e81
 	}
 
 	importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
 	importCmd.Stdin = strings.NewReader(out)
5ff122f7
 	out, _, err = runCommandWithOutput(importCmd)
 	if err != nil {
dc944ea7
 		c.Fatalf("failed to import image: %s, %v", out, err)
5ff122f7
 	}
 
475c6531
 	cleanedImageID := strings.TrimSpace(out)
a268e367
 	if cleanedImageID == "" {
 		c.Fatalf("output should have been an image id, got: %s", out)
5ff122f7
 	}
 }