(t *testing.T)
| 198 | } |
| 199 | |
| 200 | func TestTag(t *testing.T) { |
| 201 | // Note: this will resolve pull from the GCR registry (see |
| 202 | // testdata/registries.conf). |
| 203 | busyboxLatest := "docker.io/library/busybox:latest" |
| 204 | |
| 205 | runtime, cleanup := testNewRuntime(t) |
| 206 | defer cleanup() |
| 207 | ctx := context.Background() |
| 208 | |
| 209 | pullOptions := &PullOptions{} |
| 210 | pullOptions.Writer = os.Stdout |
| 211 | pulledImages, err := runtime.Pull(ctx, busyboxLatest, config.PullPolicyMissing, pullOptions) |
| 212 | require.NoError(t, err) |
| 213 | require.Len(t, pulledImages, 1) |
| 214 | |
| 215 | image := pulledImages[0] |
| 216 | |
| 217 | digest := "sha256:adab3844f497ab9171f070d4cae4114b5aec565ac772e2f2579405b78be67c96" |
| 218 | |
| 219 | // Tag |
| 220 | for _, test := range []struct { |
| 221 | tag string |
| 222 | resolvesTo string |
| 223 | expectError bool |
| 224 | }{ |
| 225 | {"foo", "localhost/foo:latest", false}, |
| 226 | {"docker.io/foo", "docker.io/library/foo:latest", false}, |
| 227 | {"quay.io/bar/foo:tag", "quay.io/bar/foo:tag", false}, |
| 228 | {"registry.com/$invalid", "", true}, |
| 229 | {digest, "", true}, |
| 230 | {"foo@" + digest, "", true}, |
| 231 | {"quay.io/foo@" + digest, "", true}, |
| 232 | {"", "", true}, |
| 233 | } { |
| 234 | err := image.Tag(test.tag) |
| 235 | if test.expectError { |
| 236 | require.Error(t, err, "tag should have failed: %v", test) |
| 237 | continue |
| 238 | } |
| 239 | require.NoError(t, err, "tag should have succeeded: %v", test) |
| 240 | |
| 241 | _, resolvedName, err := runtime.LookupImage(test.tag, nil) |
| 242 | require.NoError(t, err, "image should have resolved locally: %v", test) |
| 243 | require.Equal(t, test.resolvesTo, resolvedName, "image should have resolved correctly: %v", test) |
| 244 | } |
| 245 | |
| 246 | // Check for specific error. |
| 247 | err = image.Tag("foo@" + digest) |
| 248 | require.True(t, errors.Cause(err) == errTagDigest, "check for specific digest error") |
| 249 | } |
| 250 | |
| 251 | func TestUntag(t *testing.T) { |
| 252 | // Note: this will resolve pull from the GCR registry (see |
nothing calls this directly
no test coverage detected
searching dependent graphs…