Skip to content

Commit

Permalink
c8d integration: skip TestImportWithCustomPlatform
Browse files Browse the repository at this point in the history
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 <laurabrehm@hey.com>
  • Loading branch information
laurazard committed Oct 16, 2023
1 parent 670bc0a commit 6f625ae
Showing 1 changed file with 57 additions and 22 deletions.
79 changes: 57 additions & 22 deletions integration/image/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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{
Expand All @@ -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",
Expand All @@ -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)
})
}
}

0 comments on commit 6f625ae

Please sign in to comment.