From 6f625ae65afe4791fe7968cfb92579f140d76b7f Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Mon, 16 Oct 2023 12:13:51 +0100 Subject: [PATCH] c8d integration: skip TestImportWithCustomPlatform We support importing images for other platforms when using the containerd image store, so we shouldn't validate the image OS on import. This commit also splits the test into two, so that we can keep running the "success" import with a custom platform tests running w/ c8d while skipping the "error/rejection" test cases. Signed-off-by: Laura Brehm --- integration/image/import_test.go | 77 +++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/integration/image/import_test.go b/integration/image/import_test.go index d38d65c542..b624498533 100644 --- a/integration/image/import_test.go +++ b/integration/image/import_test.go @@ -67,10 +67,9 @@ func TestImportWithCustomPlatform(t *testing.T) { imageRdr := io.MultiReader(&tarBuffer, io.LimitReader(testutil.DevZero, 0)) tests := []struct { - name string - platform string - expected image.V1Image - expectedErr string + name string + platform string + expected image.V1Image }{ { platform: "", @@ -79,14 +78,6 @@ func TestImportWithCustomPlatform(t *testing.T) { Architecture: runtime.GOARCH, // this may fail on armhf due to normalization? }, }, - { - platform: " ", - expectedErr: "is an invalid component", - }, - { - platform: "/", - expectedErr: "is an invalid component", - }, { platform: runtime.GOOS, expected: image.V1Image{ @@ -108,6 +99,58 @@ func TestImportWithCustomPlatform(t *testing.T) { Architecture: "sparc64", }, }, + } + + for i, tc := range tests { + tc := tc + t.Run(tc.platform, func(t *testing.T) { + ctx := testutil.StartSpan(ctx, t) + reference := "import-with-platform:tc-" + strconv.Itoa(i) + + _, err = client.ImageImport(ctx, + types.ImageImportSource{Source: imageRdr, SourceName: "-"}, + reference, + types.ImageImportOptions{Platform: tc.platform}) + assert.NilError(t, err) + + inspect, _, err := client.ImageInspectWithRaw(ctx, reference) + assert.NilError(t, err) + assert.Equal(t, inspect.Os, tc.expected.OS) + assert.Equal(t, inspect.Architecture, tc.expected.Architecture) + }) + } +} + +func TestImportWithCustomPlatformReject(t *testing.T) { + skip.If(t, testEnv.DaemonInfo.OSType == "windows", "TODO enable on windows") + skip.If(t, testEnv.UsingSnapshotter(), "we support importing images/other platforms w/ containerd image store") + + ctx := setupTest(t) + + client := testEnv.APIClient() + + // Construct an empty tar archive. + var tarBuffer bytes.Buffer + + tw := tar.NewWriter(&tarBuffer) + err := tw.Close() + assert.NilError(t, err) + imageRdr := io.MultiReader(&tarBuffer, io.LimitReader(testutil.DevZero, 0)) + + tests := []struct { + name string + platform string + expected image.V1Image + expectedErr string + }{ + { + platform: " ", + expectedErr: "is an invalid component", + }, + { + platform: "/", + expectedErr: "is an invalid component", + }, { platform: "macos", expectedErr: "operating system is not supported", @@ -134,16 +177,8 @@ func TestImportWithCustomPlatform(t *testing.T) { types.ImageImportSource{Source: imageRdr, SourceName: "-"}, reference, types.ImageImportOptions{Platform: tc.platform}) - if tc.expectedErr != "" { - assert.ErrorContains(t, err, tc.expectedErr) - } else { - assert.NilError(t, err) - inspect, _, err := client.ImageInspectWithRaw(ctx, reference) - assert.NilError(t, err) - assert.Equal(t, inspect.Os, tc.expected.OS) - assert.Equal(t, inspect.Architecture, tc.expected.Architecture) - } + assert.ErrorContains(t, err, tc.expectedErr) }) } }