Browse Source

update save-load-unix-test

Signed-off-by: xlgao-zju <xlgao@zju.edu.cn>
xlgao-zju 9 years ago
parent
commit
8d98b37031
1 changed files with 11 additions and 26 deletions
  1. 11 26
      integration-cli/docker_cli_save_load_unix_test.go

+ 11 - 26
integration-cli/docker_cli_save_load_unix_test.go

@@ -3,11 +3,11 @@
 package main
 
 import (
-	"bytes"
 	"io/ioutil"
 	"os"
 	"os/exec"
 
+	"github.com/docker/docker/pkg/integration/checker"
 	"github.com/go-check/check"
 	"github.com/kr/pty"
 )
@@ -29,9 +29,8 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
 	saveCmd := exec.Command(dockerBinary, "save", repoName)
 	saveCmd.Stdout = tmpFile
 
-	if _, err = runCommand(saveCmd); err != nil {
-		c.Fatalf("failed to save repo: %v", err)
-	}
+	_, err = runCommand(saveCmd)
+	c.Assert(err, check.IsNil)
 
 	tmpFile, err = os.Open(tmpFile.Name())
 	c.Assert(err, check.IsNil)
@@ -41,41 +40,27 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
 	loadCmd := exec.Command(dockerBinary, "load")
 	loadCmd.Stdin = tmpFile
 
-	if out, _, err = runCommandWithOutput(loadCmd); err != nil {
-		c.Fatalf("failed to load repo: %s, %v", out, err)
-	}
+	out, _, err = runCommandWithOutput(loadCmd)
+	c.Assert(err, check.IsNil, check.Commentf(out))
 
 	after, _ := dockerCmd(c, "inspect", repoName)
 
-	if before != after {
-		c.Fatalf("inspect is not the same after a save / load")
-	}
+	c.Assert(before, check.Equals, after) //inspect is not the same after a save / load
 
 	deleteImages(repoName)
 
 	pty, tty, err := pty.Open()
-	if err != nil {
-		c.Fatalf("Could not open pty: %v", err)
-	}
+	c.Assert(err, check.IsNil)
 	cmd := exec.Command(dockerBinary, "save", repoName)
 	cmd.Stdin = tty
 	cmd.Stdout = tty
 	cmd.Stderr = tty
-	if err := cmd.Start(); err != nil {
-		c.Fatalf("start err: %v", err)
-	}
-	if err := cmd.Wait(); err == nil {
-		c.Fatal("did not break writing to a TTY")
-	}
+	c.Assert(cmd.Start(), check.IsNil)
+	c.Assert(cmd.Wait(), check.NotNil) //did not break writing to a TTY
 
 	buf := make([]byte, 1024)
 
 	n, err := pty.Read(buf)
-	if err != nil {
-		c.Fatal("could not read tty output")
-	}
-
-	if !bytes.Contains(buf[:n], []byte("Cowardly refusing")) {
-		c.Fatal("help output is not being yielded", out)
-	}
+	c.Assert(err, check.IsNil) //could not read tty output
+	c.Assert(string(buf[:n]), checker.Contains, "Cowardly refusing", check.Commentf("help output is not being yielded", out))
 }