(t *testing.T)
| 42 | ) |
| 43 | |
| 44 | func TestExportAllCases(t *testing.T) { |
| 45 | if testing.Short() { |
| 46 | t.Skip() |
| 47 | } |
| 48 | |
| 49 | for _, tc := range []struct { |
| 50 | name string |
| 51 | prepare func(context.Context, *testing.T, *Client) images.Image |
| 52 | check func(context.Context, *testing.T, *Client, *os.File, images.Image) |
| 53 | }{ |
| 54 | { |
| 55 | name: "export all platforms without SkipMissing", |
| 56 | prepare: func(ctx context.Context, t *testing.T, client *Client) images.Image { |
| 57 | if runtime.GOOS == "windows" { |
| 58 | t.Skip("skipping test on windows - the testimage index has only one platform") |
| 59 | } |
| 60 | img, err := client.Fetch(ctx, testImage, WithPlatform(platforms.DefaultString()), WithAllMetadata()) |
| 61 | if err != nil { |
| 62 | t.Fatal(err) |
| 63 | } |
| 64 | return img |
| 65 | }, |
| 66 | check: func(ctx context.Context, t *testing.T, client *Client, dstFile *os.File, _ images.Image) { |
| 67 | err := client.Export(ctx, dstFile, archive.WithImage(client.ImageService(), testImage), archive.WithPlatform(platforms.All)) |
| 68 | if !errdefs.IsNotFound(err) { |
| 69 | t.Fatal("should fail with not found error") |
| 70 | } |
| 71 | }, |
| 72 | }, |
| 73 | { |
| 74 | name: "export all platforms with SkipMissing", |
| 75 | prepare: func(ctx context.Context, t *testing.T, client *Client) images.Image { |
| 76 | if runtime.GOOS == "windows" { |
| 77 | t.Skip("skipping test on windows - the testimage index has only one platform") |
| 78 | } |
| 79 | img, err := client.Fetch(ctx, testImage, WithPlatform(platforms.DefaultString()), WithAllMetadata()) |
| 80 | if err != nil { |
| 81 | t.Fatal(err) |
| 82 | } |
| 83 | return img |
| 84 | }, |
| 85 | check: func(ctx context.Context, t *testing.T, client *Client, dstFile *os.File, img images.Image) { |
| 86 | defaultPlatformManifest, err := getPlatformManifest(ctx, client.ContentStore(), img.Target, platforms.Default()) |
| 87 | if err != nil { |
| 88 | t.Fatal(err) |
| 89 | } |
| 90 | err = client.Export(ctx, dstFile, archive.WithImage(client.ImageService(), testImage), archive.WithPlatform(platforms.All), archive.WithSkipMissing(client.ContentStore())) |
| 91 | if err != nil { |
| 92 | t.Fatal(err) |
| 93 | } |
| 94 | dstFile.Seek(0, 0) |
| 95 | assertOCITar(t, dstFile, true) |
| 96 | |
| 97 | // Check if archive contains only one manifest for the default platform |
| 98 | if !isImageInArchive(ctx, t, client, dstFile, defaultPlatformManifest) { |
| 99 | t.Fatal("archive does not contain manifest for the default platform") |
| 100 | } |
| 101 |
nothing calls this directly
no test coverage detected
searching dependent graphs…