Merge pull request #11907 from gcuisinier/11094-allow-import-from-file2

fix #11094 - Allow 'docker import' to load from local files
This commit is contained in:
Sebastiaan van Stijn
2015-06-20 12:17:58 -07:00
4 changed files with 90 additions and 10 deletions
+56
View File
@@ -1,6 +1,9 @@
package main
import (
"bufio"
"io/ioutil"
"os"
"os/exec"
"strings"
@@ -50,3 +53,56 @@ func (s *DockerSuite) TestImportBadURL(c *check.C) {
c.Fatalf("expected an error msg but didn't get one:\n%s", out)
}
}
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")
}
}