Applying #16756 to integration-cli/docker_cli_by_digest_test.go
Signed-off-by: Aditi Rajagopal <arajagopal@us.ibm.com>
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"github.com/docker/distribution/digest" |
| 10 | 10 |
"github.com/docker/distribution/manifest/schema1" |
| 11 | 11 |
"github.com/docker/docker/api/types" |
| 12 |
+ "github.com/docker/docker/pkg/integration/checker" |
|
| 12 | 13 |
"github.com/docker/docker/pkg/stringutils" |
| 13 | 14 |
"github.com/docker/docker/utils" |
| 14 | 15 |
"github.com/go-check/check" |
| ... | ... |
@@ -32,30 +33,23 @@ func setupImageWithTag(c *check.C, tag string) (digest.Digest, error) {
|
| 32 | 32 |
|
| 33 | 33 |
// tag the image to upload it to the private registry |
| 34 | 34 |
repoAndTag := utils.ImageReference(repoName, tag) |
| 35 |
- if out, _, err := dockerCmdWithError("commit", containerName, repoAndTag); err != nil {
|
|
| 36 |
- return "", fmt.Errorf("image tagging failed: %s, %v", out, err)
|
|
| 37 |
- } |
|
| 35 |
+ out, _, err := dockerCmdWithError("commit", containerName, repoAndTag)
|
|
| 36 |
+ c.Assert(err, checker.IsNil, check.Commentf("image tagging failed: %s", out))
|
|
| 38 | 37 |
|
| 39 | 38 |
// delete the container as we don't need it any more |
| 40 |
- if err := deleteContainer(containerName); err != nil {
|
|
| 41 |
- return "", err |
|
| 42 |
- } |
|
| 39 |
+ err = deleteContainer(containerName) |
|
| 40 |
+ c.Assert(err, checker.IsNil) |
|
| 43 | 41 |
|
| 44 | 42 |
// push the image |
| 45 |
- out, _, err := dockerCmdWithError("push", repoAndTag)
|
|
| 46 |
- if err != nil {
|
|
| 47 |
- return "", fmt.Errorf("pushing the image to the private registry has failed: %s, %v", out, err)
|
|
| 48 |
- } |
|
| 43 |
+ out, _, err = dockerCmdWithError("push", repoAndTag)
|
|
| 44 |
+ c.Assert(err, checker.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out))
|
|
| 49 | 45 |
|
| 50 | 46 |
// delete our local repo that we previously tagged |
| 51 |
- if rmiout, _, err := dockerCmdWithError("rmi", repoAndTag); err != nil {
|
|
| 52 |
- return "", fmt.Errorf("error deleting images prior to real test: %s, %v", rmiout, err)
|
|
| 53 |
- } |
|
| 47 |
+ rmiout, _, err := dockerCmdWithError("rmi", repoAndTag)
|
|
| 48 |
+ c.Assert(err, checker.IsNil, check.Commentf("error deleting images prior to real test: %s", rmiout))
|
|
| 54 | 49 |
|
| 55 | 50 |
matches := pushDigestRegex.FindStringSubmatch(out) |
| 56 |
- if len(matches) != 2 {
|
|
| 57 |
- return "", fmt.Errorf("unable to parse digest from push output: %s", out)
|
|
| 58 |
- } |
|
| 51 |
+ c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from push output: %s", out))
|
|
| 59 | 52 |
pushDigest := matches[1] |
| 60 | 53 |
|
| 61 | 54 |
return digest.Digest(pushDigest), nil |
| ... | ... |
@@ -64,32 +58,24 @@ func setupImageWithTag(c *check.C, tag string) (digest.Digest, error) {
|
| 64 | 64 |
func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) {
|
| 65 | 65 |
testRequires(c, DaemonIsLinux) |
| 66 | 66 |
pushDigest, err := setupImage(c) |
| 67 |
- if err != nil {
|
|
| 68 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 69 |
- } |
|
| 67 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 70 | 68 |
|
| 71 | 69 |
// pull from the registry using the tag |
| 72 | 70 |
out, _ := dockerCmd(c, "pull", repoName) |
| 73 | 71 |
|
| 74 | 72 |
// the pull output includes "Digest: <digest>", so find that |
| 75 | 73 |
matches := digestRegex.FindStringSubmatch(out) |
| 76 |
- if len(matches) != 2 {
|
|
| 77 |
- c.Fatalf("unable to parse digest from pull output: %s", out)
|
|
| 78 |
- } |
|
| 74 |
+ c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
|
|
| 79 | 75 |
pullDigest := matches[1] |
| 80 | 76 |
|
| 81 | 77 |
// make sure the pushed and pull digests match |
| 82 |
- if pushDigest.String() != pullDigest {
|
|
| 83 |
- c.Fatalf("push digest %q didn't match pull digest %q", pushDigest, pullDigest)
|
|
| 84 |
- } |
|
| 78 |
+ c.Assert(pushDigest.String(), checker.Equals, pullDigest) |
|
| 85 | 79 |
} |
| 86 | 80 |
|
| 87 | 81 |
func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) {
|
| 88 | 82 |
testRequires(c, DaemonIsLinux) |
| 89 | 83 |
pushDigest, err := setupImage(c) |
| 90 |
- if err != nil {
|
|
| 91 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 92 |
- } |
|
| 84 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 93 | 85 |
|
| 94 | 86 |
// pull from the registry using the <name>@<digest> reference |
| 95 | 87 |
imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
|
| ... | ... |
@@ -97,15 +83,11 @@ func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) {
|
| 97 | 97 |
|
| 98 | 98 |
// the pull output includes "Digest: <digest>", so find that |
| 99 | 99 |
matches := digestRegex.FindStringSubmatch(out) |
| 100 |
- if len(matches) != 2 {
|
|
| 101 |
- c.Fatalf("unable to parse digest from pull output: %s", out)
|
|
| 102 |
- } |
|
| 100 |
+ c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
|
|
| 103 | 101 |
pullDigest := matches[1] |
| 104 | 102 |
|
| 105 | 103 |
// make sure the pushed and pull digests match |
| 106 |
- if pushDigest.String() != pullDigest {
|
|
| 107 |
- c.Fatalf("push digest %q didn't match pull digest %q", pushDigest, pullDigest)
|
|
| 108 |
- } |
|
| 104 |
+ c.Assert(pushDigest.String(), checker.Equals, pullDigest) |
|
| 109 | 105 |
} |
| 110 | 106 |
|
| 111 | 107 |
func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *check.C) {
|
| ... | ... |
@@ -113,16 +95,13 @@ func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *check.C) {
|
| 113 | 113 |
// pull from the registry using the <name>@<digest> reference |
| 114 | 114 |
imageReference := fmt.Sprintf("%s@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", repoName)
|
| 115 | 115 |
out, _, err := dockerCmdWithError("pull", imageReference)
|
| 116 |
- if err == nil || !strings.Contains(out, "manifest unknown") {
|
|
| 117 |
- c.Fatalf("expected non-zero exit status and correct error message when pulling non-existing image: %s", out)
|
|
| 118 |
- } |
|
| 116 |
+ c.Assert(err, checker.NotNil, check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image"))
|
|
| 117 |
+ c.Assert(out, checker.Contains, "manifest unknown", check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image"))
|
|
| 119 | 118 |
} |
| 120 | 119 |
|
| 121 | 120 |
func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
|
| 122 | 121 |
pushDigest, err := setupImage(c) |
| 123 |
- if err != nil {
|
|
| 124 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 125 |
- } |
|
| 122 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 126 | 123 |
|
| 127 | 124 |
imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
|
| 128 | 125 |
|
| ... | ... |
@@ -130,19 +109,13 @@ func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) {
|
| 130 | 130 |
out, _ := dockerCmd(c, "create", "--name", containerName, imageReference) |
| 131 | 131 |
|
| 132 | 132 |
res, err := inspectField(containerName, "Config.Image") |
| 133 |
- if err != nil {
|
|
| 134 |
- c.Fatalf("failed to get Config.Image: %s, %v", out, err)
|
|
| 135 |
- } |
|
| 136 |
- if res != imageReference {
|
|
| 137 |
- c.Fatalf("unexpected Config.Image: %s (expected %s)", res, imageReference)
|
|
| 138 |
- } |
|
| 133 |
+ c.Assert(err, checker.IsNil, check.Commentf("failed to get Config.Image: %s", out))
|
|
| 134 |
+ c.Assert(res, checker.Equals, imageReference) |
|
| 139 | 135 |
} |
| 140 | 136 |
|
| 141 | 137 |
func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
|
| 142 | 138 |
pushDigest, err := setupImage(c) |
| 143 |
- if err != nil {
|
|
| 144 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 145 |
- } |
|
| 139 |
+ c.Assert(err, checker.IsNil) |
|
| 146 | 140 |
|
| 147 | 141 |
imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
|
| 148 | 142 |
|
| ... | ... |
@@ -151,27 +124,17 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
|
| 151 | 151 |
|
| 152 | 152 |
foundRegex := regexp.MustCompile("found=([^\n]+)")
|
| 153 | 153 |
matches := foundRegex.FindStringSubmatch(out) |
| 154 |
- if len(matches) != 2 {
|
|
| 155 |
- c.Fatalf("error locating expected 'found=1' output: %s", out)
|
|
| 156 |
- } |
|
| 157 |
- if matches[1] != "1" {
|
|
| 158 |
- c.Fatalf("Expected %q, got %q", "1", matches[1])
|
|
| 159 |
- } |
|
| 154 |
+ c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
|
|
| 155 |
+ c.Assert(matches[1], checker.Equals, "1", check.Commentf("Expected %q, got %q", "1", matches[1]))
|
|
| 160 | 156 |
|
| 161 | 157 |
res, err := inspectField(containerName, "Config.Image") |
| 162 |
- if err != nil {
|
|
| 163 |
- c.Fatalf("failed to get Config.Image: %s, %v", out, err)
|
|
| 164 |
- } |
|
| 165 |
- if res != imageReference {
|
|
| 166 |
- c.Fatalf("unexpected Config.Image: %s (expected %s)", res, imageReference)
|
|
| 167 |
- } |
|
| 158 |
+ c.Assert(err, checker.IsNil, check.Commentf("failed to get Config.Image: %s", out))
|
|
| 159 |
+ c.Assert(res, checker.Equals, imageReference) |
|
| 168 | 160 |
} |
| 169 | 161 |
|
| 170 | 162 |
func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
|
| 171 | 163 |
digest, err := setupImage(c) |
| 172 |
- if err != nil {
|
|
| 173 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 174 |
- } |
|
| 164 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 175 | 165 |
|
| 176 | 166 |
imageReference := fmt.Sprintf("%s@%s", repoName, digest)
|
| 177 | 167 |
|
| ... | ... |
@@ -179,28 +142,23 @@ func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
|
| 179 | 179 |
dockerCmd(c, "pull", imageReference) |
| 180 | 180 |
|
| 181 | 181 |
// make sure inspect runs ok |
| 182 |
- if _, err := inspectField(imageReference, "Id"); err != nil {
|
|
| 183 |
- c.Fatalf("failed to inspect image: %v", err)
|
|
| 184 |
- } |
|
| 182 |
+ _, err = inspectField(imageReference, "Id") |
|
| 183 |
+ c.Assert(err, checker.IsNil, check.Commentf("failed to inspect image"))
|
|
| 185 | 184 |
|
| 186 | 185 |
// do the delete |
| 187 |
- if err := deleteImages(imageReference); err != nil {
|
|
| 188 |
- c.Fatalf("unexpected error deleting image: %v", err)
|
|
| 189 |
- } |
|
| 186 |
+ err = deleteImages(imageReference) |
|
| 187 |
+ c.Assert(err, checker.IsNil, check.Commentf("unexpected error deleting image"))
|
|
| 190 | 188 |
|
| 191 | 189 |
// try to inspect again - it should error this time |
| 192 |
- if _, err := inspectField(imageReference, "Id"); err == nil {
|
|
| 193 |
- c.Fatalf("unexpected nil err trying to inspect what should be a non-existent image")
|
|
| 194 |
- } else if !strings.Contains(err.Error(), "No such image") {
|
|
| 195 |
- c.Fatalf("expected 'No such image' output, got %v", err)
|
|
| 196 |
- } |
|
| 190 |
+ _, err = inspectField(imageReference, "Id") |
|
| 191 |
+ //unexpected nil err trying to inspect what should be a non-existent image |
|
| 192 |
+ c.Assert(err, checker.NotNil) |
|
| 193 |
+ c.Assert(err.Error(), checker.Contains, "No such image") |
|
| 197 | 194 |
} |
| 198 | 195 |
|
| 199 | 196 |
func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
|
| 200 | 197 |
digest, err := setupImage(c) |
| 201 |
- if err != nil {
|
|
| 202 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 203 |
- } |
|
| 198 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 204 | 199 |
|
| 205 | 200 |
imageReference := fmt.Sprintf("%s@%s", repoName, digest)
|
| 206 | 201 |
|
| ... | ... |
@@ -209,9 +167,7 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
|
| 209 | 209 |
|
| 210 | 210 |
// get the image id |
| 211 | 211 |
imageID, err := inspectField(imageReference, "Id") |
| 212 |
- if err != nil {
|
|
| 213 |
- c.Fatalf("error getting image id: %v", err)
|
|
| 214 |
- } |
|
| 212 |
+ c.Assert(err, checker.IsNil, check.Commentf("error getting image id"))
|
|
| 215 | 213 |
|
| 216 | 214 |
// do the build |
| 217 | 215 |
name := "buildbydigest" |
| ... | ... |
@@ -219,26 +175,18 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
|
| 219 | 219 |
`FROM %s |
| 220 | 220 |
CMD ["/bin/echo", "Hello World"]`, imageReference), |
| 221 | 221 |
true) |
| 222 |
- if err != nil {
|
|
| 223 |
- c.Fatal(err) |
|
| 224 |
- } |
|
| 222 |
+ c.Assert(err, checker.IsNil) |
|
| 225 | 223 |
|
| 226 | 224 |
// get the build's image id |
| 227 | 225 |
res, err := inspectField(name, "Config.Image") |
| 228 |
- if err != nil {
|
|
| 229 |
- c.Fatal(err) |
|
| 230 |
- } |
|
| 226 |
+ c.Assert(err, checker.IsNil) |
|
| 231 | 227 |
// make sure they match |
| 232 |
- if res != imageID {
|
|
| 233 |
- c.Fatalf("Image %s, expected %s", res, imageID)
|
|
| 234 |
- } |
|
| 228 |
+ c.Assert(res, checker.Equals, imageID) |
|
| 235 | 229 |
} |
| 236 | 230 |
|
| 237 | 231 |
func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
|
| 238 | 232 |
digest, err := setupImage(c) |
| 239 |
- if err != nil {
|
|
| 240 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 241 |
- } |
|
| 233 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 242 | 234 |
|
| 243 | 235 |
imageReference := fmt.Sprintf("%s@%s", repoName, digest)
|
| 244 | 236 |
|
| ... | ... |
@@ -250,25 +198,16 @@ func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) {
|
| 250 | 250 |
dockerCmd(c, "tag", imageReference, tag) |
| 251 | 251 |
|
| 252 | 252 |
expectedID, err := inspectField(imageReference, "Id") |
| 253 |
- if err != nil {
|
|
| 254 |
- c.Fatalf("error getting original image id: %v", err)
|
|
| 255 |
- } |
|
| 253 |
+ c.Assert(err, checker.IsNil, check.Commentf("error getting original image id"))
|
|
| 256 | 254 |
|
| 257 | 255 |
tagID, err := inspectField(tag, "Id") |
| 258 |
- if err != nil {
|
|
| 259 |
- c.Fatalf("error getting tagged image id: %v", err)
|
|
| 260 |
- } |
|
| 261 |
- |
|
| 262 |
- if tagID != expectedID {
|
|
| 263 |
- c.Fatalf("expected image id %q, got %q", expectedID, tagID)
|
|
| 264 |
- } |
|
| 256 |
+ c.Assert(err, checker.IsNil, check.Commentf("error getting tagged image id"))
|
|
| 257 |
+ c.Assert(tagID, checker.Equals, expectedID) |
|
| 265 | 258 |
} |
| 266 | 259 |
|
| 267 | 260 |
func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
|
| 268 | 261 |
digest, err := setupImage(c) |
| 269 |
- if err != nil {
|
|
| 270 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 271 |
- } |
|
| 262 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 272 | 263 |
|
| 273 | 264 |
imageReference := fmt.Sprintf("%s@%s", repoName, digest)
|
| 274 | 265 |
|
| ... | ... |
@@ -276,20 +215,14 @@ func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
|
| 276 | 276 |
dockerCmd(c, "pull", imageReference) |
| 277 | 277 |
|
| 278 | 278 |
out, _ := dockerCmd(c, "images") |
| 279 |
- |
|
| 280 |
- if strings.Contains(out, "DIGEST") {
|
|
| 281 |
- c.Fatalf("list output should not have contained DIGEST header: %s", out)
|
|
| 282 |
- } |
|
| 283 |
- |
|
| 279 |
+ c.Assert(out, checker.Not(checker.Contains), "DIGEST", check.Commentf("list output should not have contained DIGEST header"))
|
|
| 284 | 280 |
} |
| 285 | 281 |
|
| 286 | 282 |
func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
| 287 | 283 |
|
| 288 | 284 |
// setup image1 |
| 289 | 285 |
digest1, err := setupImageWithTag(c, "tag1") |
| 290 |
- if err != nil {
|
|
| 291 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 292 |
- } |
|
| 286 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 293 | 287 |
imageReference1 := fmt.Sprintf("%s@%s", repoName, digest1)
|
| 294 | 288 |
c.Logf("imageReference1 = %s", imageReference1)
|
| 295 | 289 |
|
| ... | ... |
@@ -301,15 +234,11 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
| 301 | 301 |
|
| 302 | 302 |
// make sure repo shown, tag=<none>, digest = $digest1 |
| 303 | 303 |
re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`) |
| 304 |
- if !re1.MatchString(out) {
|
|
| 305 |
- c.Fatalf("expected %q: %s", re1.String(), out)
|
|
| 306 |
- } |
|
| 307 |
- |
|
| 304 |
+ c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
|
|
| 308 | 305 |
// setup image2 |
| 309 | 306 |
digest2, err := setupImageWithTag(c, "tag2") |
| 310 |
- if err != nil {
|
|
| 311 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 312 |
- } |
|
| 307 |
+ //error setting up image |
|
| 308 |
+ c.Assert(err, checker.IsNil) |
|
| 313 | 309 |
imageReference2 := fmt.Sprintf("%s@%s", repoName, digest2)
|
| 314 | 310 |
c.Logf("imageReference2 = %s", imageReference2)
|
| 315 | 311 |
|
| ... | ... |
@@ -323,15 +252,11 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
| 323 | 323 |
out, _ = dockerCmd(c, "images", "--digests") |
| 324 | 324 |
|
| 325 | 325 |
// make sure repo shown, tag=<none>, digest = $digest1 |
| 326 |
- if !re1.MatchString(out) {
|
|
| 327 |
- c.Fatalf("expected %q: %s", re1.String(), out)
|
|
| 328 |
- } |
|
| 326 |
+ c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
|
|
| 329 | 327 |
|
| 330 | 328 |
// make sure repo shown, tag=<none>, digest = $digest2 |
| 331 | 329 |
re2 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest2.String() + `\s`) |
| 332 |
- if !re2.MatchString(out) {
|
|
| 333 |
- c.Fatalf("expected %q: %s", re2.String(), out)
|
|
| 334 |
- } |
|
| 330 |
+ c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
|
|
| 335 | 331 |
|
| 336 | 332 |
// pull tag1 |
| 337 | 333 |
dockerCmd(c, "pull", repoName+":tag1") |
| ... | ... |
@@ -342,16 +267,10 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
| 342 | 342 |
// make sure image 1 has repo, tag, <none> AND repo, <none>, digest |
| 343 | 343 |
reWithTag1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*<none>\s`) |
| 344 | 344 |
reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`) |
| 345 |
- if !reWithTag1.MatchString(out) {
|
|
| 346 |
- c.Fatalf("expected %q: %s", reWithTag1.String(), out)
|
|
| 347 |
- } |
|
| 348 |
- if !reWithDigest1.MatchString(out) {
|
|
| 349 |
- c.Fatalf("expected %q: %s", reWithDigest1.String(), out)
|
|
| 350 |
- } |
|
| 345 |
+ c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
|
|
| 346 |
+ c.Assert(reWithTag1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithTag1.String(), out))
|
|
| 351 | 347 |
// make sure image 2 has repo, <none>, digest |
| 352 |
- if !re2.MatchString(out) {
|
|
| 353 |
- c.Fatalf("expected %q: %s", re2.String(), out)
|
|
| 354 |
- } |
|
| 348 |
+ c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
|
|
| 355 | 349 |
|
| 356 | 350 |
// pull tag 2 |
| 357 | 351 |
dockerCmd(c, "pull", repoName+":tag2") |
| ... | ... |
@@ -360,41 +279,29 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
|
| 360 | 360 |
out, _ = dockerCmd(c, "images", "--digests") |
| 361 | 361 |
|
| 362 | 362 |
// make sure image 1 has repo, tag, digest |
| 363 |
- if !reWithTag1.MatchString(out) {
|
|
| 364 |
- c.Fatalf("expected %q: %s", re1.String(), out)
|
|
| 365 |
- } |
|
| 363 |
+ c.Assert(reWithTag1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithTag1.String(), out))
|
|
| 366 | 364 |
|
| 367 | 365 |
// make sure image 2 has repo, tag, digest |
| 368 | 366 |
reWithTag2 := regexp.MustCompile(`\s*` + repoName + `\s*tag2\s*<none>\s`) |
| 369 | 367 |
reWithDigest2 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest2.String() + `\s`) |
| 370 |
- if !reWithTag2.MatchString(out) {
|
|
| 371 |
- c.Fatalf("expected %q: %s", reWithTag2.String(), out)
|
|
| 372 |
- } |
|
| 373 |
- if !reWithDigest2.MatchString(out) {
|
|
| 374 |
- c.Fatalf("expected %q: %s", reWithDigest2.String(), out)
|
|
| 375 |
- } |
|
| 368 |
+ c.Assert(reWithTag2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithTag2.String(), out))
|
|
| 369 |
+ c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out))
|
|
| 376 | 370 |
|
| 377 | 371 |
// list images |
| 378 | 372 |
out, _ = dockerCmd(c, "images", "--digests") |
| 379 | 373 |
|
| 380 | 374 |
// make sure image 1 has repo, tag, digest |
| 381 |
- if !reWithTag1.MatchString(out) {
|
|
| 382 |
- c.Fatalf("expected %q: %s", re1.String(), out)
|
|
| 383 |
- } |
|
| 375 |
+ c.Assert(reWithTag1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithTag1.String(), out))
|
|
| 384 | 376 |
// make sure image 2 has repo, tag, digest |
| 385 |
- if !reWithTag2.MatchString(out) {
|
|
| 386 |
- c.Fatalf("expected %q: %s", re2.String(), out)
|
|
| 387 |
- } |
|
| 377 |
+ c.Assert(reWithTag2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithTag2.String(), out))
|
|
| 388 | 378 |
// make sure busybox has tag, but not digest |
| 389 | 379 |
busyboxRe := regexp.MustCompile(`\s*busybox\s*latest\s*<none>\s`) |
| 390 |
- if !busyboxRe.MatchString(out) {
|
|
| 391 |
- c.Fatalf("expected %q: %s", busyboxRe.String(), out)
|
|
| 392 |
- } |
|
| 380 |
+ c.Assert(busyboxRe.MatchString(out), checker.True, check.Commentf("expected %q: %s", busyboxRe.String(), out))
|
|
| 393 | 381 |
} |
| 394 | 382 |
|
| 395 | 383 |
func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *check.C) {
|
| 396 | 384 |
digest, err := setupImage(c) |
| 397 |
- c.Assert(err, check.IsNil, check.Commentf("error setting up image: %v", err))
|
|
| 385 |
+ c.Assert(err, check.IsNil, check.Commentf("error setting up image"))
|
|
| 398 | 386 |
|
| 399 | 387 |
imageReference := fmt.Sprintf("%s@%s", repoName, digest)
|
| 400 | 388 |
|
| ... | ... |
@@ -404,18 +311,16 @@ func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *check.C) {
|
| 404 | 404 |
out, _ := dockerCmd(c, "inspect", imageReference) |
| 405 | 405 |
|
| 406 | 406 |
var imageJSON []types.ImageInspect |
| 407 |
- if err = json.Unmarshal([]byte(out), &imageJSON); err != nil {
|
|
| 408 |
- c.Fatalf("unable to unmarshal body for latest version: %v", err)
|
|
| 409 |
- } |
|
| 410 |
- |
|
| 411 |
- c.Assert(len(imageJSON), check.Equals, 1) |
|
| 412 |
- c.Assert(len(imageJSON[0].RepoDigests), check.Equals, 1) |
|
| 413 |
- c.Assert(stringutils.InSlice(imageJSON[0].RepoDigests, imageReference), check.Equals, true) |
|
| 407 |
+ err = json.Unmarshal([]byte(out), &imageJSON) |
|
| 408 |
+ c.Assert(err, checker.IsNil) |
|
| 409 |
+ c.Assert(imageJSON, checker.HasLen, 1) |
|
| 410 |
+ c.Assert(imageJSON[0].RepoDigests, checker.HasLen, 1) |
|
| 411 |
+ c.Assert(stringutils.InSlice(imageJSON[0].RepoDigests, imageReference), checker.Equals, true) |
|
| 414 | 412 |
} |
| 415 | 413 |
|
| 416 | 414 |
func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c *check.C) {
|
| 417 | 415 |
digest, err := setupImage(c) |
| 418 |
- c.Assert(err, check.IsNil, check.Commentf("error setting up image: %v", err))
|
|
| 416 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 419 | 417 |
|
| 420 | 418 |
imageReference := fmt.Sprintf("%s@%s", repoName, digest)
|
| 421 | 419 |
|
| ... | ... |
@@ -427,7 +332,7 @@ func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c |
| 427 | 427 |
_, err = buildImage(imageName1, fmt.Sprintf( |
| 428 | 428 |
`FROM %s |
| 429 | 429 |
LABEL match me 1`, imageReference), true) |
| 430 |
- c.Assert(err, check.IsNil) |
|
| 430 |
+ c.Assert(err, checker.IsNil) |
|
| 431 | 431 |
|
| 432 | 432 |
// run a container based on that |
| 433 | 433 |
out, _ := dockerCmd(c, "run", "-d", imageReference, "echo", "hello") |
| ... | ... |
@@ -441,9 +346,8 @@ func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c |
| 441 | 441 |
|
| 442 | 442 |
// Invalid imageReference |
| 443 | 443 |
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", fmt.Sprintf("--filter=ancestor=busybox@%s", digest))
|
| 444 |
- if strings.TrimSpace(out) != "" {
|
|
| 445 |
- c.Fatalf("Expected filter container for %s ancestor filter to be empty, got %v", fmt.Sprintf("busybox@%s", digest), strings.TrimSpace(out))
|
|
| 446 |
- } |
|
| 444 |
+ // Filter container for ancestor filter should be empty |
|
| 445 |
+ c.Assert(strings.TrimSpace(out), checker.Equals, "") |
|
| 447 | 446 |
|
| 448 | 447 |
// Valid imageReference |
| 449 | 448 |
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+imageReference) |
| ... | ... |
@@ -452,9 +356,7 @@ func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c |
| 452 | 452 |
|
| 453 | 453 |
func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) {
|
| 454 | 454 |
pushDigest, err := setupImage(c) |
| 455 |
- if err != nil {
|
|
| 456 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 457 |
- } |
|
| 455 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 458 | 456 |
|
| 459 | 457 |
// pull from the registry using the <name>@<digest> reference |
| 460 | 458 |
imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest)
|
| ... | ... |
@@ -462,9 +364,7 @@ func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) |
| 462 | 462 |
// just in case... |
| 463 | 463 |
|
| 464 | 464 |
imageID, err := inspectField(imageReference, "Id") |
| 465 |
- if err != nil {
|
|
| 466 |
- c.Fatalf("error inspecting image id: %v", err)
|
|
| 467 |
- } |
|
| 465 |
+ c.Assert(err, checker.IsNil, check.Commentf("error inspecting image id"))
|
|
| 468 | 466 |
|
| 469 | 467 |
dockerCmd(c, "rmi", imageID) |
| 470 | 468 |
} |
| ... | ... |
@@ -474,17 +374,14 @@ func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) |
| 474 | 474 |
func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
|
| 475 | 475 |
testRequires(c, DaemonIsLinux) |
| 476 | 476 |
manifestDigest, err := setupImage(c) |
| 477 |
- if err != nil {
|
|
| 478 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 479 |
- } |
|
| 477 |
+ c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
|
|
| 480 | 478 |
|
| 481 | 479 |
// Load the target manifest blob. |
| 482 | 480 |
manifestBlob := s.reg.readBlobContents(c, manifestDigest) |
| 483 | 481 |
|
| 484 | 482 |
var imgManifest schema1.Manifest |
| 485 |
- if err := json.Unmarshal(manifestBlob, &imgManifest); err != nil {
|
|
| 486 |
- c.Fatalf("unable to decode image manifest from blob: %s", err)
|
|
| 487 |
- } |
|
| 483 |
+ err = json.Unmarshal(manifestBlob, &imgManifest) |
|
| 484 |
+ c.Assert(err, checker.IsNil, check.Commentf("unable to decode image manifest from blob"))
|
|
| 488 | 485 |
|
| 489 | 486 |
// Change a layer in the manifest. |
| 490 | 487 |
imgManifest.FSLayers[0] = schema1.FSLayer{
|
| ... | ... |
@@ -497,9 +394,7 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
|
| 497 | 497 |
defer undo() |
| 498 | 498 |
|
| 499 | 499 |
alteredManifestBlob, err := json.MarshalIndent(imgManifest, "", " ") |
| 500 |
- if err != nil {
|
|
| 501 |
- c.Fatalf("unable to encode altered image manifest to JSON: %s", err)
|
|
| 502 |
- } |
|
| 500 |
+ c.Assert(err, checker.IsNil, check.Commentf("unable to encode altered image manifest to JSON"))
|
|
| 503 | 501 |
|
| 504 | 502 |
s.reg.writeBlobContents(c, manifestDigest, alteredManifestBlob) |
| 505 | 503 |
|
| ... | ... |
@@ -509,14 +404,10 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
|
| 509 | 509 |
// Pull from the registry using the <name>@<digest> reference. |
| 510 | 510 |
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
|
| 511 | 511 |
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
|
| 512 |
- if exitStatus == 0 {
|
|
| 513 |
- c.Fatalf("expected a non-zero exit status but got %d: %s", exitStatus, out)
|
|
| 514 |
- } |
|
| 512 |
+ c.Assert(exitStatus, checker.Not(check.Equals), 0) |
|
| 515 | 513 |
|
| 516 | 514 |
expectedErrorMsg := fmt.Sprintf("image verification failed for digest %s", manifestDigest)
|
| 517 |
- if !strings.Contains(out, expectedErrorMsg) {
|
|
| 518 |
- c.Fatalf("expected error message %q in output: %s", expectedErrorMsg, out)
|
|
| 519 |
- } |
|
| 515 |
+ c.Assert(out, checker.Contains, expectedErrorMsg) |
|
| 520 | 516 |
} |
| 521 | 517 |
|
| 522 | 518 |
// TestPullFailsWithAlteredLayer tests that a `docker pull` fails when |
| ... | ... |
@@ -524,17 +415,14 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
|
| 524 | 524 |
func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
|
| 525 | 525 |
testRequires(c, DaemonIsLinux) |
| 526 | 526 |
manifestDigest, err := setupImage(c) |
| 527 |
- if err != nil {
|
|
| 528 |
- c.Fatalf("error setting up image: %v", err)
|
|
| 529 |
- } |
|
| 527 |
+ c.Assert(err, checker.IsNil) |
|
| 530 | 528 |
|
| 531 | 529 |
// Load the target manifest blob. |
| 532 | 530 |
manifestBlob := s.reg.readBlobContents(c, manifestDigest) |
| 533 | 531 |
|
| 534 | 532 |
var imgManifest schema1.Manifest |
| 535 |
- if err := json.Unmarshal(manifestBlob, &imgManifest); err != nil {
|
|
| 536 |
- c.Fatalf("unable to decode image manifest from blob: %s", err)
|
|
| 537 |
- } |
|
| 533 |
+ err = json.Unmarshal(manifestBlob, &imgManifest) |
|
| 534 |
+ c.Assert(err, checker.IsNil) |
|
| 538 | 535 |
|
| 539 | 536 |
// Next, get the digest of one of the layers from the manifest. |
| 540 | 537 |
targetLayerDigest := imgManifest.FSLayers[0].BlobSum |
| ... | ... |
@@ -553,12 +441,8 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
|
| 553 | 553 |
// Pull from the registry using the <name>@<digest> reference. |
| 554 | 554 |
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
|
| 555 | 555 |
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
|
| 556 |
- if exitStatus == 0 {
|
|
| 557 |
- c.Fatalf("expected a zero exit status but got: %d", exitStatus)
|
|
| 558 |
- } |
|
| 556 |
+ c.Assert(exitStatus, checker.Not(check.Equals), 0, check.Commentf("expected a zero exit status"))
|
|
| 559 | 557 |
|
| 560 | 558 |
expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest)
|
| 561 |
- if !strings.Contains(out, expectedErrorMsg) {
|
|
| 562 |
- c.Fatalf("expected error message %q in output: %s", expectedErrorMsg, out)
|
|
| 563 |
- } |
|
| 559 |
+ c.Assert(out, checker.Contains, expectedErrorMsg, check.Commentf("expected error message in output: %s", out))
|
|
| 564 | 560 |
} |