Repository: moby/moby
File: integration/image/import_test.go (Go)

Code before:
	_, err = client.ImageImport(ctx,
		imagetypes.ImportSource{Source: imageRdr, SourceName: "-"},
		reference,
		imagetypes.ImportOptions{})
	assert.NilError(t, err)
}

func TestImportWithCustomPlatform(t *testing.T) {
	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "TODO enable on windows")

	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
	}{
		{
			platform: "",
			expected: image.V1Image{
				OS:           runtime.GOOS,
				Architecture: runtime.GOARCH, // this may fail on armhf due to normalization?
			},
		},
		{
			platform: runtime.GOOS,
			expected: image.V1Image{
				OS:           runtime.GOOS,
				Architecture: runtime.GOARCH, // this may fail on armhf due to normalization?
			},
		},
		{
			platform: strings.ToUpper(runtime.GOOS),
			expected: image.V1Image{
				OS:           runtime.GOOS,
				Architecture: runtime.GOARCH, // this may fail on armhf due to normalization?
			},
		},
		{
			platform: runtime.GOOS + "/sparc64",
			expected: image.V1Image{

Review comment (bug):
Heh, yes, looks like I somehow picked the wrong type here in the first place in https://github.com/moby/moby/commit/01ae9525dd7d3e1fac7bd1b05f1d3286d853ff3a (https://github.com/moby/moby/pull/43103). This is using `client.ImageInspect`, which returns an API type `image.InspectResponse` https://github.com/moby/moby/blob/20ed15f607f5764f3bfda4894d7ecbf7e2a77c2e/client/image_inspect.go#L15

Not sure how I ended up with that; possibly I had the test somewhere internal to the daemon?

_Technically_ even `Platform` doesn't make sense here, as `image.InspectResponse` does not have / embed a platform, but has its own fields. I guess this was wishful thinking on my side that we'd eventually be able to migrate that type to do so :thinking_face: https://github.com/moby/moby/blob/20ed15f607f5764f3bfda4894d7ecbf7e2a77c2e/api/types/image/image_inspect.go#L93-L101


Code after:
	_, err = client.ImageImport(ctx,
		imagetypes.ImportSource{Source: imageRdr, SourceName: "-"},
		reference,
		imagetypes.ImportOptions{})
	assert.NilError(t, err)
}

func TestImportWithCustomPlatform(t *testing.T) {
	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "TODO enable on windows")

	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 platforms.Platform
	}{
		{
			platform: "",
			expected: platforms.Platform{
				OS:           runtime.GOOS,
				Architecture: runtime.GOARCH, // this may fail on armhf due to normalization?
			},
		},
		{
			platform: runtime.GOOS,
			expected: platforms.Platform{
				OS:           runtime.GOOS,
				Architecture: runtime.GOARCH, // this may fail on armhf due to normalization?
			},
		},
		{
			platform: strings.ToUpper(runtime.GOOS),
			expected: platforms.Platform{
				OS:           runtime.GOOS,
				Architecture: runtime.GOARCH, // this may fail on armhf due to normalization?
			},
		},
		{
			platform: runtime.GOOS + "/sparc64",
			expected: platforms.Platform{