mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 21:21:42 +00:00
adding message option to the import subcommand
Signed-off-by: Taylor Jones <monitorjbl@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/go-check/check"
|
||||
@@ -72,6 +73,49 @@ func (s *DockerSuite) TestImportFile(c *check.C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
|
||||
dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
|
||||
|
||||
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", err)
|
||||
}
|
||||
|
||||
message := "Testing commit message"
|
||||
out, _ := dockerCmd(c, "import", "-m", message, temporaryFile.Name())
|
||||
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)
|
||||
|
||||
out, _ = dockerCmd(c, "history", image)
|
||||
split := strings.Split(out, "\n")
|
||||
|
||||
if len(split) != 3 {
|
||||
c.Fatalf("expected 3 lines from image history, got %d", len(split))
|
||||
}
|
||||
r := regexp.MustCompile("[\\s]{2,}")
|
||||
split = r.Split(split[1], -1)
|
||||
|
||||
if message != split[3] {
|
||||
c.Fatalf("expected %s in commit message, got %s", message, split[3])
|
||||
}
|
||||
|
||||
out, _ = dockerCmd(c, "run", "--rm", image, "true")
|
||||
if out != "" {
|
||||
c.Fatalf("command output should've been nothing, was %q", out)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
|
||||
_, exitCode, err := dockerCmdWithError("import", "example.com/myImage.tar")
|
||||
if exitCode == 0 || err == nil {
|
||||
|
||||
Reference in New Issue
Block a user