File: platform_matcher_test.go

package info (click to toggle)
golang-github-containers-image 5.28.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,104 kB
  • sloc: sh: 194; makefile: 73
file content (61 lines) | stat: -rw-r--r-- 2,036 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package platform

import (
	"fmt"
	"testing"

	"github.com/containers/image/v5/types"
	imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
	"github.com/stretchr/testify/assert"
)

func TestWantedPlatforms(t *testing.T) {
	for _, c := range []struct {
		ctx      types.SystemContext
		expected []imgspecv1.Platform
	}{
		{ // X86_64 does not have variants
			types.SystemContext{ArchitectureChoice: "amd64", OSChoice: "linux"},
			[]imgspecv1.Platform{
				{OS: "linux", Architecture: "amd64", Variant: ""},
			},
		},
		{ // ARM with variant
			types.SystemContext{ArchitectureChoice: "arm", OSChoice: "linux", VariantChoice: "v6"},
			[]imgspecv1.Platform{
				{OS: "linux", Architecture: "arm", Variant: "v6"},
				{OS: "linux", Architecture: "arm", Variant: "v5"},
				{OS: "linux", Architecture: "arm", Variant: ""},
			},
		},
		{ // ARM without variant
			types.SystemContext{ArchitectureChoice: "arm", OSChoice: "linux"},
			[]imgspecv1.Platform{
				{OS: "linux", Architecture: "arm", Variant: ""},
				{OS: "linux", Architecture: "arm", Variant: "v8"},
				{OS: "linux", Architecture: "arm", Variant: "v7"},
				{OS: "linux", Architecture: "arm", Variant: "v6"},
				{OS: "linux", Architecture: "arm", Variant: "v5"},
			},
		},
		{ // ARM64 has a base variant
			types.SystemContext{ArchitectureChoice: "arm64", OSChoice: "linux"},
			[]imgspecv1.Platform{
				{OS: "linux", Architecture: "arm64", Variant: ""},
				{OS: "linux", Architecture: "arm64", Variant: "v8"},
			},
		},
		{ // Custom (completely unrecognized data)
			types.SystemContext{ArchitectureChoice: "armel", OSChoice: "freeBSD", VariantChoice: "custom"},
			[]imgspecv1.Platform{
				{OS: "freeBSD", Architecture: "armel", Variant: "custom"},
				{OS: "freeBSD", Architecture: "armel", Variant: ""},
			},
		},
	} {
		testName := fmt.Sprintf("%q/%q/%q", c.ctx.ArchitectureChoice, c.ctx.OSChoice, c.ctx.VariantChoice)
		platforms, err := WantedPlatforms(&c.ctx)
		assert.Nil(t, err, testName)
		assert.Equal(t, c.expected, platforms, testName)
	}
}