Skip to content

Commit

Permalink
Merge pull request moby#46652 from laurazard/fix-test-import-custom-i…
Browse files Browse the repository at this point in the history
…mage-custom-plat

c8d integration: skip TestImportWithCustomPlatform
  • Loading branch information
thaJeztah authored Oct 17, 2023
2 parents f6576e9 + 6f625ae commit b85185e
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 b85185e

Please sign in to comment.