From 288214e5aecefd5477678e3dfb3f3fed0dcab23b Mon Sep 17 00:00:00 2001 From: liaoqingwei Date: Tue, 20 Oct 2015 18:27:52 +0800 Subject: [PATCH] Use of checkers on docker_cli_import_test.go. Signed-off-by: liaoqingwei --- integration-cli/docker_cli_import_test.go | 69 +++++++---------------- 1 file changed, 19 insertions(+), 50 deletions(-) diff --git a/integration-cli/docker_cli_import_test.go b/integration-cli/docker_cli_import_test.go index 83746e2b61..4352817285 100644 --- a/integration-cli/docker_cli_import_test.go +++ b/integration-cli/docker_cli_import_test.go @@ -8,6 +8,7 @@ import ( "regexp" "strings" + "github.com/docker/docker/pkg/integration/checker" "github.com/go-check/check" ) @@ -20,30 +21,20 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) { exec.Command(dockerBinary, "export", cleanedContainerID), exec.Command(dockerBinary, "import", "-"), ) - if err != nil { - c.Errorf("import failed with errors: %v, output: %q", err, out) - } + c.Assert(err, checker.IsNil) + + c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't")) - 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, "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) { testRequires(c, DaemonIsLinux) 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) { @@ -51,29 +42,21 @@ func (s *DockerSuite) TestImportFile(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) - } + c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file")) 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) - } + c.Assert(err, checker.IsNil, check.Commentf("failed to export a container")) 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) 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) { @@ -81,48 +64,34 @@ 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) - } + c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file")) 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) - } + c.Assert(err, checker.IsNil, check.Commentf("failed to export a container")) 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) - } + c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't")) 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)) - } + c.Assert(split, checker.HasLen, 3, check.Commentf("expected 3 lines from image history")) 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]) - } + c.Assert(message, checker.Equals, split[3], check.Commentf("didn't get expected value in commit message")) 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) { - _, 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")) }