2014-11-20 00:19:16 -05:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2015-05-16 14:04:25 -04:00
|
|
|
"io/ioutil"
|
2014-11-20 00:19:16 -05:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2015-06-04 12:02:14 -04:00
|
|
|
"github.com/kr/pty"
|
2014-11-20 00:19:16 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// save a repo and try to load it using stdout
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
|
2015-05-16 10:59:53 -04:00
|
|
|
name := "test-save-and-load-repo-stdout"
|
2015-07-21 14:01:24 -04:00
|
|
|
dockerCmd(c, "run", "--name", name, "busybox", "true")
|
2014-11-20 00:19:16 -05:00
|
|
|
|
|
|
|
repoName := "foobar-save-load-test"
|
2015-07-21 14:01:24 -04:00
|
|
|
out, _ := dockerCmd(c, "commit", name, repoName)
|
2014-11-20 00:19:16 -05:00
|
|
|
|
2015-07-21 14:01:24 -04:00
|
|
|
before, _ := dockerCmd(c, "inspect", repoName)
|
2014-11-20 00:19:16 -05:00
|
|
|
|
2015-05-16 14:04:25 -04:00
|
|
|
tmpFile, err := ioutil.TempFile("", "foobar-save-load-test.tar")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
defer os.Remove(tmpFile.Name())
|
|
|
|
|
|
|
|
saveCmd := exec.Command(dockerBinary, "save", repoName)
|
|
|
|
saveCmd.Stdout = tmpFile
|
|
|
|
|
|
|
|
if _, err = runCommand(saveCmd); err != nil {
|
|
|
|
c.Fatalf("failed to save repo: %v", err)
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
|
2015-05-16 14:04:25 -04:00
|
|
|
tmpFile, err = os.Open(tmpFile.Name())
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2014-11-20 00:19:16 -05:00
|
|
|
deleteImages(repoName)
|
|
|
|
|
2015-05-16 14:04:25 -04:00
|
|
|
loadCmd := exec.Command(dockerBinary, "load")
|
|
|
|
loadCmd.Stdin = tmpFile
|
|
|
|
|
2014-11-20 00:19:16 -05:00
|
|
|
if out, _, err = runCommandWithOutput(loadCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to load repo: %s, %v", out, err)
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
|
2015-07-21 14:01:24 -04:00
|
|
|
after, _ := dockerCmd(c, "inspect", repoName)
|
2014-11-20 00:19:16 -05:00
|
|
|
|
|
|
|
if before != after {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("inspect is not the same after a save / load")
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteImages(repoName)
|
|
|
|
|
|
|
|
pty, tty, err := pty.Open()
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not open pty: %v", err)
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
cmd := exec.Command(dockerBinary, "save", repoName)
|
|
|
|
cmd.Stdin = tty
|
|
|
|
cmd.Stdout = tty
|
|
|
|
cmd.Stderr = tty
|
|
|
|
if err := cmd.Start(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("start err: %v", err)
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
if err := cmd.Wait(); err == nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("did not break writing to a TTY")
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
buf := make([]byte, 1024)
|
|
|
|
|
|
|
|
n, err := pty.Read(buf)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("could not read tty output")
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Contains(buf[:n], []byte("Cowardly refusing")) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("help output is not being yielded", out)
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
}
|