MCPcopy
hub / github.com/containerd/containerd / TestImagePullWithDistSourceLabel

Function TestImagePullWithDistSourceLabel

integration/client/image_test.go:83–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func 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
138func TestImageUsage(t *testing.T) {
139 if testing.Short() {

Callers

nothing calls this directly

Calls 11

testContextFunction · 0.85
newClientFunction · 0.85
WithPlatformMatcherFunction · 0.85
FatalMethod · 0.80
CloseMethod · 0.65
PullMethod · 0.65
DeleteMethod · 0.65
ImageServiceMethod · 0.65
ContentStoreMethod · 0.65
InfoMethod · 0.65
TargetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…