mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use of checkers on docker_cli_history_test.go
Signed-off-by: James Carey <jecarey@us.ibm.com>
This commit is contained in:
parent
e2d263d64e
commit
04b6b0b47f
1 changed files with 10 additions and 21 deletions
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue