github.com/damirazo/docker@v1.9.0/integration-cli/docker_cli_save_load_unix_test.go (about) 1 // +build !windows 2 3 package main 4 5 import ( 6 "io/ioutil" 7 "os" 8 "os/exec" 9 10 "github.com/docker/docker/pkg/integration/checker" 11 "github.com/go-check/check" 12 "github.com/kr/pty" 13 ) 14 15 // save a repo and try to load it using stdout 16 func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) { 17 name := "test-save-and-load-repo-stdout" 18 dockerCmd(c, "run", "--name", name, "busybox", "true") 19 20 repoName := "foobar-save-load-test" 21 out, _ := dockerCmd(c, "commit", name, repoName) 22 23 before, _ := dockerCmd(c, "inspect", repoName) 24 25 tmpFile, err := ioutil.TempFile("", "foobar-save-load-test.tar") 26 c.Assert(err, check.IsNil) 27 defer os.Remove(tmpFile.Name()) 28 29 saveCmd := exec.Command(dockerBinary, "save", repoName) 30 saveCmd.Stdout = tmpFile 31 32 _, err = runCommand(saveCmd) 33 c.Assert(err, check.IsNil) 34 35 tmpFile, err = os.Open(tmpFile.Name()) 36 c.Assert(err, check.IsNil) 37 38 deleteImages(repoName) 39 40 loadCmd := exec.Command(dockerBinary, "load") 41 loadCmd.Stdin = tmpFile 42 43 out, _, err = runCommandWithOutput(loadCmd) 44 c.Assert(err, check.IsNil, check.Commentf(out)) 45 46 after, _ := dockerCmd(c, "inspect", repoName) 47 48 c.Assert(before, check.Equals, after) //inspect is not the same after a save / load 49 50 deleteImages(repoName) 51 52 pty, tty, err := pty.Open() 53 c.Assert(err, check.IsNil) 54 cmd := exec.Command(dockerBinary, "save", repoName) 55 cmd.Stdin = tty 56 cmd.Stdout = tty 57 cmd.Stderr = tty 58 c.Assert(cmd.Start(), check.IsNil) 59 c.Assert(cmd.Wait(), check.NotNil) //did not break writing to a TTY 60 61 buf := make([]byte, 1024) 62 63 n, err := pty.Read(buf) 64 c.Assert(err, check.IsNil) //could not read tty output 65 c.Assert(string(buf[:n]), checker.Contains, "Cowardly refusing", check.Commentf("help output is not being yielded", out)) 66 }