github.com/squaremo/docker@v1.3.2-0.20150516120342-42cfc9554972/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  }
    42  
    43  func (s *DockerSuite) TestImportBadURL(c *check.C) {
    44  	runCmd := exec.Command(dockerBinary, "import", "http://nourl/bad")
    45  	out, _, err := runCommandWithOutput(runCmd)
    46  	if err == nil {
    47  		c.Fatal("import was supposed to fail but didn't")
    48  	}
    49  	if !strings.Contains(out, "dial tcp") {
    50  		c.Fatalf("expected an error msg but didn't get one:\n%s", out)
    51  	}
    52  }