MCPcopy Create free account
hub / github.com/containers/common / TestTag

Function TestTag

libimage/image_test.go:200–249  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

198}
199
200func 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
251func TestUntag(t *testing.T) {
252 // Note: this will resolve pull from the GCR registry (see

Callers

nothing calls this directly

Calls 7

testNewRuntimeFunction · 0.85
PullMethod · 0.80
TagMethod · 0.80
LookupImageMethod · 0.80
LenMethod · 0.65
cleanupFunction · 0.50
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…