Browse Source

Use of checkers on docker_cli_import_test.go.

Signed-off-by: liaoqingwei <liaoqingwei@huawei.com>
liaoqingwei 9 years ago
parent
commit
288214e5ae
1 changed files with 19 additions and 50 deletions
  1. 19 50
      integration-cli/docker_cli_import_test.go

+ 19 - 50
integration-cli/docker_cli_import_test.go

@@ -8,6 +8,7 @@ import (
 	"regexp"
 	"regexp"
 	"strings"
 	"strings"
 
 
+	"github.com/docker/docker/pkg/integration/checker"
 	"github.com/go-check/check"
 	"github.com/go-check/check"
 )
 )
 
 
@@ -20,30 +21,20 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
 		exec.Command(dockerBinary, "export", cleanedContainerID),
 		exec.Command(dockerBinary, "export", cleanedContainerID),
 		exec.Command(dockerBinary, "import", "-"),
 		exec.Command(dockerBinary, "import", "-"),
 	)
 	)
-	if err != nil {
-		c.Errorf("import failed with errors: %v, output: %q", err, out)
-	}
+	c.Assert(err, checker.IsNil)
 
 
-	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)
+	c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
 
 
+	image := strings.TrimSpace(out)
 	out, _ = dockerCmd(c, "run", "--rm", image, "true")
 	out, _ = dockerCmd(c, "run", "--rm", image, "true")
-	if out != "" {
-		c.Fatalf("command output should've been nothing, was %q", out)
-	}
+	c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing."))
 }
 }
 
 
 func (s *DockerSuite) TestImportBadURL(c *check.C) {
 func (s *DockerSuite) TestImportBadURL(c *check.C) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
 	out, _, err := dockerCmdWithError("import", "http://nourl/bad")
 	out, _, err := dockerCmdWithError("import", "http://nourl/bad")
-	if err == nil {
-		c.Fatal("import was supposed to fail but didn't")
-	}
-	if !strings.Contains(out, "dial tcp") {
-		c.Fatalf("expected an error msg but didn't get one:\n%s", out)
-	}
+	c.Assert(err, checker.NotNil, check.Commentf("import was supposed to fail but didn't"))
+	c.Assert(out, checker.Contains, "dial tcp", check.Commentf("expected an error msg but didn't get one"))
 }
 }
 
 
 func (s *DockerSuite) TestImportFile(c *check.C) {
 func (s *DockerSuite) TestImportFile(c *check.C) {
@@ -51,29 +42,21 @@ func (s *DockerSuite) TestImportFile(c *check.C) {
 	dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
 	dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
 
 
 	temporaryFile, err := ioutil.TempFile("", "exportImportTest")
 	temporaryFile, err := ioutil.TempFile("", "exportImportTest")
-	if err != nil {
-		c.Fatal("failed to create temporary file", "", err)
-	}
+	c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
 	defer os.Remove(temporaryFile.Name())
 	defer os.Remove(temporaryFile.Name())
 
 
 	runCmd := exec.Command(dockerBinary, "export", "test-import")
 	runCmd := exec.Command(dockerBinary, "export", "test-import")
 	runCmd.Stdout = bufio.NewWriter(temporaryFile)
 	runCmd.Stdout = bufio.NewWriter(temporaryFile)
 
 
 	_, err = runCommand(runCmd)
 	_, err = runCommand(runCmd)
-	if err != nil {
-		c.Fatal("failed to export a container", err)
-	}
+	c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
 
 
 	out, _ := dockerCmd(c, "import", temporaryFile.Name())
 	out, _ := dockerCmd(c, "import", 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)
-	}
+	c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
 	image := strings.TrimSpace(out)
 	image := strings.TrimSpace(out)
 
 
 	out, _ = dockerCmd(c, "run", "--rm", image, "true")
 	out, _ = dockerCmd(c, "run", "--rm", image, "true")
-	if out != "" {
-		c.Fatalf("command output should've been nothing, was %q", out)
-	}
+	c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing."))
 }
 }
 
 
 func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
 func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
@@ -81,48 +64,34 @@ func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
 	dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
 	dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
 
 
 	temporaryFile, err := ioutil.TempFile("", "exportImportTest")
 	temporaryFile, err := ioutil.TempFile("", "exportImportTest")
-	if err != nil {
-		c.Fatal("failed to create temporary file", "", err)
-	}
+	c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
 	defer os.Remove(temporaryFile.Name())
 	defer os.Remove(temporaryFile.Name())
 
 
 	runCmd := exec.Command(dockerBinary, "export", "test-import")
 	runCmd := exec.Command(dockerBinary, "export", "test-import")
 	runCmd.Stdout = bufio.NewWriter(temporaryFile)
 	runCmd.Stdout = bufio.NewWriter(temporaryFile)
 
 
 	_, err = runCommand(runCmd)
 	_, err = runCommand(runCmd)
-	if err != nil {
-		c.Fatal("failed to export a container", err)
-	}
+	c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
 
 
 	message := "Testing commit message"
 	message := "Testing commit message"
 	out, _ := dockerCmd(c, "import", "-m", message, temporaryFile.Name())
 	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)
-	}
+	c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
 	image := strings.TrimSpace(out)
 	image := strings.TrimSpace(out)
 
 
 	out, _ = dockerCmd(c, "history", image)
 	out, _ = dockerCmd(c, "history", image)
 	split := strings.Split(out, "\n")
 	split := strings.Split(out, "\n")
 
 
-	if len(split) != 3 {
-		c.Fatalf("expected 3 lines from image history, got %d", len(split))
-	}
+	c.Assert(split, checker.HasLen, 3, check.Commentf("expected 3 lines from image history"))
 	r := regexp.MustCompile("[\\s]{2,}")
 	r := regexp.MustCompile("[\\s]{2,}")
 	split = r.Split(split[1], -1)
 	split = r.Split(split[1], -1)
 
 
-	if message != split[3] {
-		c.Fatalf("expected %s in commit message, got %s", message, split[3])
-	}
+	c.Assert(message, checker.Equals, split[3], check.Commentf("didn't get expected value in commit message"))
 
 
 	out, _ = dockerCmd(c, "run", "--rm", image, "true")
 	out, _ = dockerCmd(c, "run", "--rm", image, "true")
-	if out != "" {
-		c.Fatalf("command output should've been nothing, was %q", out)
-	}
+	c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing"))
 }
 }
 
 
 func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
 func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
-	_, exitCode, err := dockerCmdWithError("import", "example.com/myImage.tar")
-	if exitCode == 0 || err == nil {
-		c.Fatalf("import non-existing file must failed")
-	}
+	_, _, err := dockerCmdWithError("import", "example.com/myImage.tar")
+	c.Assert(err, checker.NotNil, check.Commentf("import non-existing file must failed"))
 }
 }