2014-03-31 15:31:21 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-03-29 13:42:11 -04:00
|
|
|
"bufio"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2014-03-31 15:31:21 -04:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-03-31 15:31:21 -04:00
|
|
|
)
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestImportDisplay(c *check.C) {
|
2015-02-14 05:27:06 -05:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2014-09-12 13:10:42 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("failed to create a container", out, err)
|
2014-09-12 13:10:42 -04:00
|
|
|
}
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2015-02-14 05:27:06 -05:00
|
|
|
|
|
|
|
out, _, err = runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "export", cleanedContainerID),
|
|
|
|
exec.Command(dockerBinary, "import", "-"),
|
|
|
|
)
|
2014-09-12 09:51:21 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Errorf("import failed with errors: %v, output: %q", err, out)
|
2014-09-12 09:51:21 -04:00
|
|
|
}
|
2014-03-31 15:31:21 -04:00
|
|
|
|
2015-02-14 05:27:06 -05:00
|
|
|
if n := strings.Count(out, "\n"); n != 1 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
|
2014-03-31 15:31:21 -04:00
|
|
|
}
|
2015-02-14 05:27:06 -05:00
|
|
|
image := strings.TrimSpace(out)
|
2014-03-31 15:31:21 -04:00
|
|
|
|
2015-02-14 05:27:06 -05:00
|
|
|
runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("failed to create a container", out, err)
|
2015-02-14 05:27:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if out != "" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("command output should've been nothing, was %q", out)
|
2015-02-14 05:27:06 -05:00
|
|
|
}
|
2014-11-17 11:05:49 -05:00
|
|
|
|
2014-03-31 15:31:21 -04:00
|
|
|
}
|
2015-05-13 20:21:02 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestImportBadURL(c *check.C) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "import", "http://nourl/bad")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err == nil {
|
|
|
|
c.Fatal("import was supposed to fail but didn't")
|
|
|
|
}
|
|
|
|
if !strings.Contains(out, "dial tcp") {
|
|
|
|
c.Fatalf("expected an error msg but didn't get one:\n%s", out)
|
|
|
|
}
|
|
|
|
}
|
2015-03-29 13:42:11 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestImportFile(c *check.C) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--name", "test-import", "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal("failed to create a container", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal("failed to create temporary file", "", err)
|
|
|
|
}
|
|
|
|
defer os.Remove(temporaryFile.Name())
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "export", "test-import")
|
|
|
|
runCmd.Stdout = bufio.NewWriter(temporaryFile)
|
|
|
|
|
|
|
|
_, err = runCommand(runCmd)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal("failed to export a container", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "import", temporaryFile.Name())
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal("failed to import a container", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if n := strings.Count(out, "\n"); n != 1 {
|
|
|
|
c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
|
|
|
|
}
|
|
|
|
image := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal("failed to create a container", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if out != "" {
|
|
|
|
c.Fatalf("command output should've been nothing, was %q", out)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "import", "example.com/myImage.tar")
|
|
|
|
_, exitCode, err := runCommandWithOutput(runCmd)
|
|
|
|
if exitCode == 0 || err == nil {
|
|
|
|
c.Fatalf("import non-existing file must failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|