Browse code

integration/images: improve some asserts, and add asserts for unhandled errs

Before:

=== FAIL: amd64.integration.image TestImagePullPlatformInvalid (0.01s)
pull_test.go:37: assertion failed: expression is false: errdefs.IsInvalidParameter(err)

After:

=== RUN TestImagePullPlatformInvalid
pull_test.go:37: assertion failed: error is Error response from daemon: "foobar": unknown operating system or architecture: invalid argument (errdefs.errSystem), not errdefs.IsInvalidParameter

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/01/21 21:20:01
Showing 1 changed files
... ...
@@ -33,8 +33,8 @@ func TestImagePullPlatformInvalid(t *testing.T) {
33 33
 
34 34
 	_, err := client.ImagePull(ctx, "docker.io/library/hello-world:latest", types.ImagePullOptions{Platform: "foobar"})
35 35
 	assert.Assert(t, err != nil)
36
-	assert.ErrorContains(t, err, "unknown operating system or architecture")
37
-	assert.Assert(t, errdefs.IsInvalidParameter(err))
36
+	assert.Check(t, is.ErrorContains(err, "unknown operating system or architecture"))
37
+	assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
38 38
 }
39 39
 
40 40
 func createTestImage(ctx context.Context, t testing.TB, store content.Store) ocispec.Descriptor {
... ...
@@ -52,7 +52,7 @@ func createTestImage(ctx context.Context, t testing.TB, store content.Store) oci
52 52
 	assert.NilError(t, err)
53 53
 
54 54
 	layerDigest := w.Digest()
55
-	w.Close()
55
+	assert.Check(t, w.Close())
56 56
 
57 57
 	img := ocispec.Image{
58 58
 		Platform: platforms.DefaultSpec(),
... ...
@@ -70,7 +70,7 @@ func createTestImage(ctx context.Context, t testing.TB, store content.Store) oci
70 70
 	assert.NilError(t, w.Commit(ctx, int64(len(imgJSON)), digest.FromBytes(imgJSON)))
71 71
 
72 72
 	configDigest := w.Digest()
73
-	w.Close()
73
+	assert.Check(t, w.Close())
74 74
 
75 75
 	info, err := store.Info(ctx, layerDigest)
76 76
 	assert.NilError(t, err)
... ...
@@ -103,7 +103,7 @@ func createTestImage(ctx context.Context, t testing.TB, store content.Store) oci
103 103
 	assert.NilError(t, w.Commit(ctx, int64(len(manifestJSON)), digest.FromBytes(manifestJSON)))
104 104
 
105 105
 	manifestDigest := w.Digest()
106
-	w.Close()
106
+	assert.Check(t, w.Close())
107 107
 
108 108
 	return ocispec.Descriptor{
109 109
 		MediaType: images.MediaTypeDockerSchema2Manifest,
... ...
@@ -114,7 +114,7 @@ func createTestImage(ctx context.Context, t testing.TB, store content.Store) oci
114 114
 
115 115
 // Make sure that pulling by an already cached digest but for a different ref (that should not have that digest)
116 116
 // verifies with the remote that the digest exists in that repo.
117
-func TestImagePullStoredfDigestForOtherRepo(t *testing.T) {
117
+func TestImagePullStoredDigestForOtherRepo(t *testing.T) {
118 118
 	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
119 119
 	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "We don't run a test registry on Windows")
120 120
 	skip.If(t, testEnv.IsRootless, "Rootless has a different view of localhost (needed for test registry access)")
... ...
@@ -146,15 +146,17 @@ func TestImagePullStoredfDigestForOtherRepo(t *testing.T) {
146 146
 	rdr, err := client.ImagePull(ctx, remote, types.ImagePullOptions{})
147 147
 	assert.NilError(t, err)
148 148
 	defer rdr.Close()
149
-	io.Copy(io.Discard, rdr)
149
+	_, err = io.Copy(io.Discard, rdr)
150
+	assert.Check(t, err)
150 151
 
151 152
 	// Now, pull a totally different repo with a the same digest
152 153
 	rdr, err = client.ImagePull(ctx, path.Join(registry.DefaultURL, "other:image@"+desc.Digest.String()), types.ImagePullOptions{})
153 154
 	if rdr != nil {
154
-		rdr.Close()
155
+		assert.Check(t, rdr.Close())
155 156
 	}
156 157
 	assert.Assert(t, err != nil, "Expected error, got none: %v", err)
157 158
 	assert.Assert(t, errdefs.IsNotFound(err), err)
159
+	assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
158 160
 }
159 161
 
160 162
 // TestImagePullNonExisting pulls non-existing images from the central registry, with different
... ...
@@ -184,7 +186,7 @@ func TestImagePullNonExisting(t *testing.T) {
184 184
 			}
185 185
 
186 186
 			expectedMsg := fmt.Sprintf("pull access denied for %s, repository does not exist or may require 'docker login'", "asdfasdf")
187
-			assert.Assert(t, is.ErrorContains(err, expectedMsg))
187
+			assert.Check(t, is.ErrorContains(err, expectedMsg))
188 188
 			assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
189 189
 			if all {
190 190
 				// pull -a on a nonexistent registry should fall back as well