Signed-off-by: James Carey <jecarey@us.ibm.com>
| ... | ... |
@@ -14,10 +14,8 @@ import ( |
| 14 | 14 |
|
| 15 | 15 |
func (s *DockerSuite) TestImagesEnsureImageIsListed(c *check.C) {
|
| 16 | 16 |
testRequires(c, DaemonIsLinux) |
| 17 |
- out, _ := dockerCmd(c, "images") |
|
| 18 |
- if !strings.Contains(out, "busybox") {
|
|
| 19 |
- c.Fatal("images should've listed busybox")
|
|
| 20 |
- } |
|
| 17 |
+ imagesOut, _ := dockerCmd(c, "images") |
|
| 18 |
+ c.Assert(imagesOut, checker.Contains, "busybox") |
|
| 21 | 19 |
} |
| 22 | 20 |
|
| 23 | 21 |
func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *check.C) {
|
| ... | ... |
@@ -32,25 +30,20 @@ func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *check.C) {
|
| 32 | 32 |
MAINTAINER dockerio1`, true) |
| 33 | 33 |
c.Assert(err, check.IsNil) |
| 34 | 34 |
|
| 35 |
- out, _ := dockerCmd(c, "images", "imagewithtag:v1") |
|
| 36 |
- |
|
| 37 |
- if !strings.Contains(out, "imagewithtag") || !strings.Contains(out, "v1") || strings.Contains(out, "v2") {
|
|
| 38 |
- c.Fatal("images should've listed imagewithtag:v1 and not imagewithtag:v2")
|
|
| 39 |
- } |
|
| 40 |
- |
|
| 41 |
- out, _ = dockerCmd(c, "images", "imagewithtag") |
|
| 35 |
+ imagesOut, _ := dockerCmd(c, "images", "imagewithtag:v1") |
|
| 36 |
+ c.Assert(imagesOut, checker.Contains, "imagewithtag") |
|
| 37 |
+ c.Assert(imagesOut, checker.Contains, "v1") |
|
| 38 |
+ c.Assert(imagesOut, checker.Not(checker.Contains), "v2") |
|
| 42 | 39 |
|
| 43 |
- if !strings.Contains(out, "imagewithtag") || !strings.Contains(out, "v1") || !strings.Contains(out, "v2") {
|
|
| 44 |
- c.Fatal("images should've listed imagewithtag:v1 and imagewithtag:v2")
|
|
| 45 |
- } |
|
| 40 |
+ imagesOut, _ = dockerCmd(c, "images", "imagewithtag") |
|
| 41 |
+ c.Assert(imagesOut, checker.Contains, "imagewithtag") |
|
| 42 |
+ c.Assert(imagesOut, checker.Contains, "v1") |
|
| 43 |
+ c.Assert(imagesOut, checker.Contains, "v2") |
|
| 46 | 44 |
} |
| 47 | 45 |
|
| 48 | 46 |
func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *check.C) {
|
| 49 |
- out, _ := dockerCmd(c, "images", "busybox:nonexistent") |
|
| 50 |
- |
|
| 51 |
- if strings.Contains(out, "busybox") {
|
|
| 52 |
- c.Fatal("images should not have listed busybox")
|
|
| 53 |
- } |
|
| 47 |
+ imagesOut, _ := dockerCmd(c, "images", "busybox:nonexistent") |
|
| 48 |
+ c.Assert(imagesOut, checker.Not(checker.Contains), "busybox") |
|
| 54 | 49 |
} |
| 55 | 50 |
|
| 56 | 51 |
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
|
| ... | ... |
@@ -58,42 +51,29 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
|
| 58 | 58 |
id1, err := buildImage("order:test_a",
|
| 59 | 59 |
`FROM scratch |
| 60 | 60 |
MAINTAINER dockerio1`, true) |
| 61 |
- if err != nil {
|
|
| 62 |
- c.Fatal(err) |
|
| 63 |
- } |
|
| 61 |
+ c.Assert(err, checker.IsNil) |
|
| 64 | 62 |
time.Sleep(1 * time.Second) |
| 65 | 63 |
id2, err := buildImage("order:test_c",
|
| 66 | 64 |
`FROM scratch |
| 67 | 65 |
MAINTAINER dockerio2`, true) |
| 68 |
- if err != nil {
|
|
| 69 |
- c.Fatal(err) |
|
| 70 |
- } |
|
| 66 |
+ c.Assert(err, checker.IsNil) |
|
| 71 | 67 |
time.Sleep(1 * time.Second) |
| 72 | 68 |
id3, err := buildImage("order:test_b",
|
| 73 | 69 |
`FROM scratch |
| 74 | 70 |
MAINTAINER dockerio3`, true) |
| 75 |
- if err != nil {
|
|
| 76 |
- c.Fatal(err) |
|
| 77 |
- } |
|
| 71 |
+ c.Assert(err, checker.IsNil) |
|
| 78 | 72 |
|
| 79 | 73 |
out, _ := dockerCmd(c, "images", "-q", "--no-trunc") |
| 80 | 74 |
imgs := strings.Split(out, "\n") |
| 81 |
- if imgs[0] != id3 {
|
|
| 82 |
- c.Fatalf("First image must be %s, got %s", id3, imgs[0])
|
|
| 83 |
- } |
|
| 84 |
- if imgs[1] != id2 {
|
|
| 85 |
- c.Fatalf("Second image must be %s, got %s", id2, imgs[1])
|
|
| 86 |
- } |
|
| 87 |
- if imgs[2] != id1 {
|
|
| 88 |
- c.Fatalf("Third image must be %s, got %s", id1, imgs[2])
|
|
| 89 |
- } |
|
| 75 |
+ c.Assert(imgs[0], checker.Equals, id3, check.Commentf("First image must be %s, got %s", id3, imgs[0]))
|
|
| 76 |
+ c.Assert(imgs[1], checker.Equals, id2, check.Commentf("First image must be %s, got %s", id2, imgs[1]))
|
|
| 77 |
+ c.Assert(imgs[2], checker.Equals, id1, check.Commentf("First image must be %s, got %s", id1, imgs[2]))
|
|
| 90 | 78 |
} |
| 91 | 79 |
|
| 92 | 80 |
func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *check.C) {
|
| 93 | 81 |
out, _, err := dockerCmdWithError("images", "-f", "FOO=123")
|
| 94 |
- if err == nil || !strings.Contains(out, "Invalid filter") {
|
|
| 95 |
- c.Fatalf("error should occur when listing images with invalid filter name FOO, %s", out)
|
|
| 96 |
- } |
|
| 82 |
+ c.Assert(err, checker.NotNil) |
|
| 83 |
+ c.Assert(out, checker.Contains, "Invalid filter") |
|
| 97 | 84 |
} |
| 98 | 85 |
|
| 99 | 86 |
func (s *DockerSuite) TestImagesFilterLabel(c *check.C) {
|
| ... | ... |
@@ -193,9 +173,8 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
|
| 193 | 193 |
dockerCmd(c, "tag", "-f", "busybox", "foobox") |
| 194 | 194 |
|
| 195 | 195 |
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true") |
| 196 |
- if e, a := 1, strings.Count(out, imageID); e != a {
|
|
| 197 |
- c.Fatalf("expected 1 dangling image, got %d: %s", a, out)
|
|
| 198 |
- } |
|
| 196 |
+ // Exect one dangling image |
|
| 197 |
+ c.Assert(strings.Count(out, imageID), checker.Equals, 1) |
|
| 199 | 198 |
} |
| 200 | 199 |
|
| 201 | 200 |
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) {
|
| ... | ... |
@@ -222,12 +201,10 @@ func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) {
|
| 222 | 222 |
intermediate := strings.TrimSpace(split[5][7:]) |
| 223 | 223 |
|
| 224 | 224 |
out, _ = dockerCmd(c, "images") |
| 225 |
- if strings.Contains(out, intermediate) {
|
|
| 226 |
- c.Fatalf("images shouldn't show non-heads images, got %s in %s", intermediate, out)
|
|
| 227 |
- } |
|
| 228 |
- if !strings.Contains(out, head[:12]) {
|
|
| 229 |
- c.Fatalf("images should contain final built images, want %s in out, got %s", head[:12], out)
|
|
| 230 |
- } |
|
| 225 |
+ // images shouldn't show non-heads images |
|
| 226 |
+ c.Assert(out, checker.Not(checker.Contains), intermediate) |
|
| 227 |
+ // images should contain final built images |
|
| 228 |
+ c.Assert(out, checker.Contains, head[:12]) |
|
| 231 | 229 |
} |
| 232 | 230 |
|
| 233 | 231 |
func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) {
|
| ... | ... |
@@ -241,7 +218,6 @@ func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) {
|
| 241 | 241 |
c.Assert(err, check.IsNil) |
| 242 | 242 |
|
| 243 | 243 |
out, _ := dockerCmd(c, "images") |
| 244 |
- if !strings.Contains(out, id[:12]) {
|
|
| 245 |
- c.Fatalf("images should contain images built from scratch (e.g. %s), got %s", id[:12], out)
|
|
| 246 |
- } |
|
| 244 |
+ // images should contain images built from scratch |
|
| 245 |
+ c.Assert(out, checker.Contains, id[:12]) |
|
| 247 | 246 |
} |