Browse code

Use of checkers in docker_cli_pull_test.go

Signed-off-by: James Carey <jecarey@us.ibm.com>

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