(t *testing.T)
| 81 | } |
| 82 | |
| 83 | func TestImagePullWithDistSourceLabel(t *testing.T) { |
| 84 | var ( |
| 85 | source = "registry.k8s.io" |
| 86 | repoName = "pause" |
| 87 | tag = "3.6" |
| 88 | ) |
| 89 | |
| 90 | ctx, cancel := testContext(t) |
| 91 | defer cancel() |
| 92 | |
| 93 | client, err := newClient(t, address) |
| 94 | if err != nil { |
| 95 | t.Fatal(err) |
| 96 | } |
| 97 | defer client.Close() |
| 98 | |
| 99 | imageName := fmt.Sprintf("%s/%s:%s", source, repoName, tag) |
| 100 | pMatcher := platforms.Default() |
| 101 | |
| 102 | // pull content without unpack and add distribution source label |
| 103 | image, err := client.Pull(ctx, imageName, WithPlatformMatcher(pMatcher)) |
| 104 | if err != nil { |
| 105 | t.Fatal(err) |
| 106 | } |
| 107 | defer client.ImageService().Delete(ctx, imageName) |
| 108 | |
| 109 | cs := client.ContentStore() |
| 110 | key := labels.LabelDistributionSource + "." + source |
| 111 | |
| 112 | // only check the target platform |
| 113 | childrenHandler := images.LimitManifests(images.ChildrenHandler(cs), pMatcher, 1) |
| 114 | |
| 115 | checkLabelHandler := func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { |
| 116 | children, err := childrenHandler(ctx, desc) |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | |
| 121 | info, err := cs.Info(ctx, desc.Digest) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | |
| 126 | // check the label |
| 127 | if got := info.Labels[key]; !strings.Contains(got, repoName) { |
| 128 | return nil, fmt.Errorf("expected to have %s repo name in label, but got %s", repoName, got) |
| 129 | } |
| 130 | return children, nil |
| 131 | } |
| 132 | |
| 133 | if err := images.Dispatch(ctx, images.HandlerFunc(checkLabelHandler), nil, image.Target()); err != nil { |
| 134 | t.Fatal(err) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | func TestImageUsage(t *testing.T) { |
| 139 | if testing.Short() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…