github.com/grubernaut/docker@v1.6.0-rc2/integration-cli/docker_cli_import_test.go (about)

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