2014-03-31 23:31:21 +04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestImportDisplay(t *testing.T) {
|
2015-02-14 13:27:06 +03:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2014-09-12 21:10:42 +04:00
|
|
|
if err != nil {
|
2015-02-14 13:27:06 +03:00
|
|
|
t.Fatal("failed to create a container", out, err)
|
2014-09-12 21:10:42 +04:00
|
|
|
}
|
2015-04-06 16:21:18 +03:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2015-02-14 13:27:06 +03:00
|
|
|
defer deleteContainer(cleanedContainerID)
|
|
|
|
|
|
|
|
out, _, err = runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "export", cleanedContainerID),
|
|
|
|
exec.Command(dockerBinary, "import", "-"),
|
|
|
|
)
|
2014-09-12 17:51:21 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("import failed with errors: %v, output: %q", err, out)
|
|
|
|
}
|
2014-03-31 23:31:21 +04:00
|
|
|
|
2015-02-14 13:27:06 +03:00
|
|
|
if n := strings.Count(out, "\n"); n != 1 {
|
|
|
|
t.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
|
2014-03-31 23:31:21 +04:00
|
|
|
}
|
2015-02-14 13:27:06 +03:00
|
|
|
image := strings.TrimSpace(out)
|
|
|
|
defer deleteImages(image)
|
2014-03-31 23:31:21 +04:00
|
|
|
|
2015-02-14 13:27:06 +03:00
|
|
|
runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("failed to create a container", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if out != "" {
|
|
|
|
t.Fatalf("command output should've been nothing, was %q", out)
|
|
|
|
}
|
2014-11-17 19:05:49 +03:00
|
|
|
|
2015-02-14 13:27:06 +03:00
|
|
|
logDone("import - display is fine, imported image runs")
|
2014-03-31 23:31:21 +04:00
|
|
|
}
|