From 04b6b0b47fab7751b716b0b6c8ce3b98a8c51e99 Mon Sep 17 00:00:00 2001 From: James Carey Date: Thu, 22 Oct 2015 13:50:58 -0500 Subject: [PATCH] Use of checkers on docker_cli_history_test.go Signed-off-by: James Carey --- integration-cli/docker_cli_history_test.go | 31 +++++++--------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/integration-cli/docker_cli_history_test.go b/integration-cli/docker_cli_history_test.go index ce9d902ed7..4dc0bb8b11 100644 --- a/integration-cli/docker_cli_history_test.go +++ b/integration-cli/docker_cli_history_test.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" + "github.com/docker/docker/pkg/integration/checker" "github.com/go-check/check" ) @@ -43,9 +44,7 @@ RUN echo "Y" RUN echo "Z"`, true) - if err != nil { - c.Fatal(err) - } + c.Assert(err, checker.IsNil) out, _ := dockerCmd(c, "history", "testbuildhistory") actualValues := strings.Split(out, "\n")[1:27] @@ -54,10 +53,7 @@ RUN echo "Z"`, for i := 0; i < 26; i++ { echoValue := fmt.Sprintf("echo \"%s\"", expectedValues[i]) actualValue := actualValues[i] - - if !strings.Contains(actualValue, echoValue) { - c.Fatalf("Expected layer \"%s\", but was: %s", expectedValues[i], actualValue) - } + c.Assert(actualValue, checker.Contains, echoValue) } } @@ -69,9 +65,7 @@ func (s *DockerSuite) TestHistoryExistentImage(c *check.C) { func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) { _, _, err := dockerCmdWithError("history", "testHistoryNonExistentImage") - if err == nil { - c.Fatal("history on a non-existent image should fail.") - } + c.Assert(err, checker.NotNil, check.Commentf("history on a non-existent image should fail.")) } func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) { @@ -91,10 +85,7 @@ func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) { out, _ := dockerCmd(c, "history", name) outputTabs := strings.Fields(strings.Split(out, "\n")[1]) actualValue := outputTabs[len(outputTabs)-1] - - if !strings.Contains(actualValue, comment) { - c.Fatalf("Expected comments %q, but found %q", comment, actualValue) - } + c.Assert(actualValue, checker.Contains, comment) } func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) { @@ -110,9 +101,9 @@ func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) { endIndex = len(lines[i]) } sizeString := lines[i][startIndex:endIndex] - if _, err := strconv.Atoi(strings.TrimSpace(sizeString)); err != nil { - c.Fatalf("The size '%s' was not an Integer", sizeString) - } + + _, err := strconv.Atoi(strings.TrimSpace(sizeString)) + c.Assert(err, checker.IsNil, check.Commentf("The size '%s' was not an Integer", sizeString)) } } @@ -121,7 +112,7 @@ func (s *DockerSuite) TestHistoryHumanOptionTrue(c *check.C) { out, _ := dockerCmd(c, "history", "--human=true", "busybox") lines := strings.Split(out, "\n") sizeColumnRegex, _ := regexp.Compile("SIZE +") - humanSizeRegex, _ := regexp.Compile("^\\d+.*B$") // Matches human sizes like 10 MB, 3.2 KB, etc + humanSizeRegexRaw := "\\d+.*B" // Matches human sizes like 10 MB, 3.2 KB, etc indices := sizeColumnRegex.FindStringIndex(lines[0]) startIndex := indices[0] endIndex := indices[1] @@ -130,8 +121,6 @@ func (s *DockerSuite) TestHistoryHumanOptionTrue(c *check.C) { endIndex = len(lines[i]) } sizeString := lines[i][startIndex:endIndex] - if matchSuccess := humanSizeRegex.MatchString(strings.TrimSpace(sizeString)); !matchSuccess { - c.Fatalf("The size '%s' was not in human format", sizeString) - } + c.Assert(strings.TrimSpace(sizeString), checker.Matches, humanSizeRegexRaw, check.Commentf("The size '%s' was not in human format", sizeString)) } }