github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/integration-cli/docker_cli_import_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os/exec"
     5  	"strings"
     6  
     7  	"github.com/go-check/check"
     8  )
     9  
    10  func (s *DockerSuite) TestImportDisplay(c *check.C) {
    11  	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
    12  	out, _, err := runCommandWithOutput(runCmd)
    13  	if err != nil {
    14  		c.Fatal("failed to create a container", out, err)
    15  	}
    16  	cleanedContainerID := strings.TrimSpace(out)
    17  
    18  	out, _, err = runCommandPipelineWithOutput(
    19  		exec.Command(dockerBinary, "export", cleanedContainerID),
    20  		exec.Command(dockerBinary, "import", "-"),
    21  	)
    22  	if err != nil {
    23  		c.Errorf("import failed with errors: %v, output: %q", err, out)
    24  	}
    25  
    26  	if n := strings.Count(out, "\n"); n != 1 {
    27  		c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
    28  	}
    29  	image := strings.TrimSpace(out)
    30  
    31  	runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
    32  	out, _, err = runCommandWithOutput(runCmd)
    33  	if err != nil {
    34  		c.Fatal("failed to create a container", out, err)
    35  	}
    36  
    37  	if out != "" {
    38  		c.Fatalf("command output should've been nothing, was %q", out)
    39  	}
    40  
    41  }