(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestImageFunctions(t *testing.T) { |
| 15 | // Note: this will resolve pull from the GCR registry (see |
| 16 | // testdata/registries.conf). |
| 17 | busybox := "docker.io/library/busybox" |
| 18 | busyboxLatest := busybox + ":latest" |
| 19 | busyboxDigest := busybox + "@" |
| 20 | |
| 21 | runtime, cleanup := testNewRuntime(t) |
| 22 | defer cleanup() |
| 23 | ctx := context.Background() |
| 24 | |
| 25 | // Pull busybox:latest, get its digest and then perform a digest pull. |
| 26 | // It's effectively pulling the same image twice but we need the digest |
| 27 | // for some of the tests below. |
| 28 | pullOptions := &PullOptions{} |
| 29 | pullOptions.Writer = os.Stdout |
| 30 | pulledImages, err := runtime.Pull(ctx, busyboxLatest, config.PullPolicyAlways, pullOptions) |
| 31 | require.NoError(t, err) |
| 32 | require.Len(t, pulledImages, 1) |
| 33 | |
| 34 | origDigest := pulledImages[0].Digest() |
| 35 | busyboxDigest += origDigest.String() |
| 36 | |
| 37 | pulledImages, err = runtime.Pull(ctx, busyboxDigest, config.PullPolicyAlways, pullOptions) |
| 38 | require.NoError(t, err) |
| 39 | require.Len(t, pulledImages, 1) |
| 40 | |
| 41 | image := pulledImages[0] |
| 42 | |
| 43 | // Note that the tests below are primarily meant to be smoke tests to |
| 44 | // catch broad regressions early on. |
| 45 | require.NoError(t, image.reload()) |
| 46 | |
| 47 | // The names history is stored in reverse order in c/storage. |
| 48 | require.Equal(t, []string{busyboxDigest, busyboxLatest}, image.Names(), "names do not match") |
| 49 | require.Equal(t, []string{busyboxLatest, busyboxDigest}, image.NamesHistory(), "names history does not match") |
| 50 | |
| 51 | require.NotNil(t, image.StorageImage()) |
| 52 | |
| 53 | // Just make sure that the ID has 64 characters. |
| 54 | require.True(t, len(image.ID()) == 64, "ID should be 64 characters long") |
| 55 | |
| 56 | // Make sure that the image we pulled by digest is the same one we |
| 57 | // pulled by tag. |
| 58 | require.Equal(t, origDigest.String(), image.Digest().String(), "digests of pulled images should match") |
| 59 | |
| 60 | // NOTE: we're recording two digests. One for the image and one for the |
| 61 | // manifest list we chose it from. |
| 62 | digests := image.Digests() |
| 63 | require.Len(t, digests, 2) |
| 64 | require.Equal(t, origDigest.String(), digests[0].String(), "first recoreded digest should be the one of the image") |
| 65 | |
| 66 | // containers/podman/issues/12729: make sure manifest lookup returns |
| 67 | // the correct error for both digests. |
| 68 | for _, digest := range digests { |
| 69 | _, err := runtime.LookupManifestList(busybox + "@" + digest.String()) |
| 70 | require.Error(t, err, "Manifest lookup should fail on an ordinary image") |
| 71 | require.Equal(t, ErrNotAManifestList, errors.Cause(err)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…