MCPcopy
hub / github.com/docker/docker-agent / TestSessionDigestResolvesPlatformIndex

Function TestSessionDigestResolvesPlatformIndex

pkg/remote/pull_test.go:356–399  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

354}
355
356func TestSessionDigestResolvesPlatformIndex(t *testing.T) {
357 t.Parallel()
358
359 amd64Image := testImage(t, "amd64")
360 arm64Image := testImage(t, "arm64")
361 amd64Digest, err := amd64Image.Digest()
362 require.NoError(t, err)
363 arm64Digest, err := arm64Image.Digest()
364 require.NoError(t, err)
365 require.NotEqual(t, amd64Digest, arm64Digest)
366
367 idx := mutate.AppendManifests(empty.Index,
368 mutate.IndexAddendum{
369 Add: amd64Image,
370 Descriptor: v1.Descriptor{Platform: &v1.Platform{
371 OS: "linux",
372 Architecture: "amd64",
373 }},
374 },
375 mutate.IndexAddendum{
376 Add: arm64Image,
377 Descriptor: v1.Descriptor{Platform: &v1.Platform{
378 OS: "linux",
379 Architecture: "arm64",
380 }},
381 },
382 )
383
384 server := httptest.NewServer(testregistry.New(testregistry.Logger(log.New(io.Discard, "", 0))))
385 defer server.Close()
386
387 registryRef := strings.TrimPrefix(server.URL, "http://") + "/platform:latest"
388 ref, err := name.ParseReference(registryRef, name.Insecure)
389 require.NoError(t, err)
390 require.NoError(t, v1remote.WriteIndex(ref, idx))
391
392 platform := &v1.Platform{OS: "linux", Architecture: "arm64"}
393 s, err := newSession(crane.GetOptions(crane.Insecure, crane.WithPlatform(platform)))
394 require.NoError(t, err)
395
396 dig, err := s.digest(t.Context(), ref)
397 require.NoError(t, err)
398 assert.Equal(t, arm64Digest.String(), dig)
399}
400
401func testImage(t *testing.T, contents string) v1.Image {
402 t.Helper()

Callers

nothing calls this directly

Calls 8

testImageFunction · 0.85
newSessionFunction · 0.85
DigestMethod · 0.80
digestMethod · 0.80
ContextMethod · 0.80
CloseMethod · 0.65
NewMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected