Use of checkers on docker_cli_history_test.go

Signed-off-by: James Carey <jecarey@us.ibm.com>
This commit is contained in:
James Carey 2015-10-22 13:50:58 -05:00
parent e2d263d64e
commit 04b6b0b47f
1 changed files with 10 additions and 21 deletions

View File

@ -6,6 +6,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -43,9 +44,7 @@ RUN echo "Y"
RUN echo "Z"`, RUN echo "Z"`,
true) true)
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err)
}
out, _ := dockerCmd(c, "history", "testbuildhistory") out, _ := dockerCmd(c, "history", "testbuildhistory")
actualValues := strings.Split(out, "\n")[1:27] actualValues := strings.Split(out, "\n")[1:27]
@ -54,10 +53,7 @@ RUN echo "Z"`,
for i := 0; i < 26; i++ { for i := 0; i < 26; i++ {
echoValue := fmt.Sprintf("echo \"%s\"", expectedValues[i]) echoValue := fmt.Sprintf("echo \"%s\"", expectedValues[i])
actualValue := actualValues[i] actualValue := actualValues[i]
c.Assert(actualValue, checker.Contains, echoValue)
if !strings.Contains(actualValue, echoValue) {
c.Fatalf("Expected layer \"%s\", but was: %s", expectedValues[i], actualValue)
}
} }
} }
@ -69,9 +65,7 @@ func (s *DockerSuite) TestHistoryExistentImage(c *check.C) {
func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) { func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) {
_, _, err := dockerCmdWithError("history", "testHistoryNonExistentImage") _, _, err := dockerCmdWithError("history", "testHistoryNonExistentImage")
if err == nil { c.Assert(err, checker.NotNil, check.Commentf("history on a non-existent image should fail."))
c.Fatal("history on a non-existent image should fail.")
}
} }
func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) { func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) {
@ -91,10 +85,7 @@ func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) {
out, _ := dockerCmd(c, "history", name) out, _ := dockerCmd(c, "history", name)
outputTabs := strings.Fields(strings.Split(out, "\n")[1]) outputTabs := strings.Fields(strings.Split(out, "\n")[1])
actualValue := outputTabs[len(outputTabs)-1] actualValue := outputTabs[len(outputTabs)-1]
c.Assert(actualValue, checker.Contains, comment)
if !strings.Contains(actualValue, comment) {
c.Fatalf("Expected comments %q, but found %q", comment, actualValue)
}
} }
func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) { func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
@ -110,9 +101,9 @@ func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
endIndex = len(lines[i]) endIndex = len(lines[i])
} }
sizeString := lines[i][startIndex:endIndex] 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") out, _ := dockerCmd(c, "history", "--human=true", "busybox")
lines := strings.Split(out, "\n") lines := strings.Split(out, "\n")
sizeColumnRegex, _ := regexp.Compile("SIZE +") 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]) indices := sizeColumnRegex.FindStringIndex(lines[0])
startIndex := indices[0] startIndex := indices[0]
endIndex := indices[1] endIndex := indices[1]
@ -130,8 +121,6 @@ func (s *DockerSuite) TestHistoryHumanOptionTrue(c *check.C) {
endIndex = len(lines[i]) endIndex = len(lines[i])
} }
sizeString := lines[i][startIndex:endIndex] sizeString := lines[i][startIndex:endIndex]
if matchSuccess := humanSizeRegex.MatchString(strings.TrimSpace(sizeString)); !matchSuccess { c.Assert(strings.TrimSpace(sizeString), checker.Matches, humanSizeRegexRaw, check.Commentf("The size '%s' was not in human format", sizeString))
c.Fatalf("The size '%s' was not in human format", sizeString)
}
} }
} }