mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #17296 from jecarey/16756-docker_cli_history_test
Use of checkers on docker_cli_history_test.go
This commit is contained in:
commit
80439a4ce2
1 changed files with 10 additions and 21 deletions
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue