Use of checkers in docker_cli_pull_test.go
| ... | ... |
@@ -30,11 +30,9 @@ func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *check.C) {
|
| 30 | 30 |
|
| 31 | 31 |
// We should have a single entry in images. |
| 32 | 32 |
img := strings.TrimSpace(s.Cmd(c, "images")) |
| 33 |
- if splitImg := strings.Split(img, "\n"); len(splitImg) != 2 {
|
|
| 34 |
- c.Fatalf("expected only two lines in the output of `docker images`, got %d", len(splitImg))
|
|
| 35 |
- } else if re := regexp.MustCompile(`^hello-world\s+latest`); !re.Match([]byte(splitImg[1])) {
|
|
| 36 |
- c.Fatal("invalid output for `docker images` (expected image and tag name")
|
|
| 37 |
- } |
|
| 33 |
+ splitImg := strings.Split(img, "\n") |
|
| 34 |
+ c.Assert(splitImg, checker.HasLen, 2) |
|
| 35 |
+ c.Assert(splitImg[1], checker.Matches, `hello-world\s+latest.*?`, check.Commentf("invalid output for `docker images` (expected image and tag name"))
|
|
| 38 | 36 |
} |
| 39 | 37 |
|
| 40 | 38 |
// TestPullNonExistingImage pulls non-existing images from the central registry, with different |
| ... | ... |
@@ -84,11 +82,9 @@ func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *chec |
| 84 | 84 |
|
| 85 | 85 |
// We should have a single entry in images. |
| 86 | 86 |
img := strings.TrimSpace(s.Cmd(c, "images")) |
| 87 |
- if splitImg := strings.Split(img, "\n"); len(splitImg) != 2 {
|
|
| 88 |
- c.Fatalf("expected only two lines in the output of `docker images`, got %d", len(splitImg))
|
|
| 89 |
- } else if re := regexp.MustCompile(`^hello-world\s+latest`); !re.Match([]byte(splitImg[1])) {
|
|
| 90 |
- c.Fatal("invalid output for `docker images` (expected image and tag name")
|
|
| 91 |
- } |
|
| 87 |
+ splitImg := strings.Split(img, "\n") |
|
| 88 |
+ c.Assert(splitImg, checker.HasLen, 2) |
|
| 89 |
+ c.Assert(splitImg[1], checker.Matches, `hello-world\s+latest.*?`, check.Commentf("invalid output for `docker images` (expected image and tag name"))
|
|
| 92 | 90 |
} |
| 93 | 91 |
|
| 94 | 92 |
// TestPullScratchNotAllowed verifies that pulling 'scratch' is rejected. |
| ... | ... |
@@ -107,13 +103,12 @@ func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *check.C) {
|
| 107 | 107 |
s.Cmd(c, "pull", "busybox") |
| 108 | 108 |
outImageCmd := s.Cmd(c, "images", "busybox") |
| 109 | 109 |
splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n") |
| 110 |
- c.Assert(splitOutImageCmd, checker.HasLen, 2, check.Commentf("expected a single entry in images\n%v", outImageCmd))
|
|
| 110 |
+ c.Assert(splitOutImageCmd, checker.HasLen, 2) |
|
| 111 | 111 |
|
| 112 | 112 |
s.Cmd(c, "pull", "--all-tags=true", "busybox") |
| 113 | 113 |
outImageAllTagCmd := s.Cmd(c, "images", "busybox") |
| 114 |
- if linesCount := strings.Count(outImageAllTagCmd, "\n"); linesCount <= 2 {
|
|
| 115 |
- c.Fatalf("pulling all tags should provide more images, got %d", linesCount-1)
|
|
| 116 |
- } |
|
| 114 |
+ linesCount := strings.Count(outImageAllTagCmd, "\n") |
|
| 115 |
+ c.Assert(linesCount, checker.GreaterThan, 2, check.Commentf("pulling all tags should provide more than two images, got %s", outImageAllTagCmd))
|
|
| 117 | 116 |
|
| 118 | 117 |
// Verify that the line for 'busybox:latest' is left unchanged. |
| 119 | 118 |
var latestLine string |
| ... | ... |
@@ -165,7 +160,6 @@ func (s *DockerHubPullSuite) TestPullClientDisconnect(c *check.C) {
|
| 165 | 165 |
c.Assert(err, checker.IsNil) |
| 166 | 166 |
|
| 167 | 167 |
time.Sleep(2 * time.Second) |
| 168 |
- if _, err := s.CmdWithError("inspect", repoName); err == nil {
|
|
| 169 |
- c.Fatal("image was pulled after client disconnected")
|
|
| 170 |
- } |
|
| 168 |
+ _, err = s.CmdWithError("inspect", repoName)
|
|
| 169 |
+ c.Assert(err, checker.NotNil, check.Commentf("image was pulled after client disconnected"))
|
|
| 171 | 170 |
} |