MCPcopy
hub / github.com/google/go-containerregistry / TestCopyWithPlatform

Function TestCopyWithPlatform

pkg/gcrane/copy_test.go:208–272  ·  view source on GitHub ↗

TestCopyWithPlatform verifies that Copy with WithPlatform resolves the multi-platform source index to the single requested manifest at the dst. Regression test for #2059.

(t *testing.T)

Source from the content-addressed store, hash-verified

206// multi-platform source index to the single requested manifest at the dst.
207// Regression test for #2059.
208func TestCopyWithPlatform(t *testing.T) {
209 s := httptest.NewServer(registry.New())
210 defer s.Close()
211 u, err := url.Parse(s.URL)
212 if err != nil {
213 t.Fatal(err)
214 }
215 src := path.Join(u.Host, "test/gcrane") + ":multi"
216 dst := path.Join(u.Host, "test/gcrane/copy") + ":amd64"
217
218 amdImg, err := random.Image(1024, 2)
219 if err != nil {
220 t.Fatal(err)
221 }
222 armImg, err := random.Image(1024, 2)
223 if err != nil {
224 t.Fatal(err)
225 }
226
227 idx := mutate.AppendManifests(empty.Index,
228 mutate.IndexAddendum{
229 Add: amdImg,
230 Descriptor: v1.Descriptor{
231 Platform: &v1.Platform{OS: "linux", Architecture: "amd64"},
232 },
233 },
234 mutate.IndexAddendum{
235 Add: armImg,
236 Descriptor: v1.Descriptor{
237 Platform: &v1.Platform{OS: "linux", Architecture: "arm64"},
238 },
239 },
240 )
241
242 srcRef, err := name.ParseReference(src)
243 if err != nil {
244 t.Fatal(err)
245 }
246 if err := remote.WriteIndex(srcRef, idx); err != nil {
247 t.Fatal(err)
248 }
249
250 if err := Copy(src, dst, WithPlatform(&v1.Platform{OS: "linux", Architecture: "amd64"})); err != nil {
251 t.Fatal(err)
252 }
253
254 dstRef, err := name.ParseReference(dst)
255 if err != nil {
256 t.Fatal(err)
257 }
258 desc, err := remote.Get(dstRef)
259 if err != nil {
260 t.Fatal(err)
261 }
262 if desc.MediaType.IsIndex() {
263 t.Fatalf("dst is an index (%s); expected a single-platform manifest", desc.MediaType)
264 }
265 amdDigest, err := amdImg.Digest()

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
ImageFunction · 0.92
AppendManifestsFunction · 0.92
ParseReferenceFunction · 0.92
WriteIndexFunction · 0.92
GetFunction · 0.92
IsIndexMethod · 0.80
CopyFunction · 0.70
WithPlatformFunction · 0.70
CloseMethod · 0.65
DigestMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…