| 1 |
package platform |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"testing" |
| 6 |
|
| 7 |
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1" |
| 8 |
"github.com/stretchr/testify/assert" |
| 9 |
"go.podman.io/image/v5/types" |
| 10 |
) |
| 11 |
|
| 12 |
func TestWantedPlatforms(t *testing.T) { |
| 13 |
for _, c := range []struct { |
| 14 |
ctx types.SystemContext |
| 15 |
expected []imgspecv1.Platform |
| 16 |
}{ |
| 17 |
{ // X86_64 does not have variants |
| 18 |
types.SystemContext{ArchitectureChoice: "amd64", OSChoice: "linux"}, |
| 19 |
[]imgspecv1.Platform{ |
| 20 |
{OS: "linux", Architecture: "amd64", Variant: ""}, |
| 21 |
}, |
| 22 |
}, |
| 23 |
{ // ARM with variant |
| 24 |
types.SystemContext{ArchitectureChoice: "arm", OSChoice: "linux", VariantChoice: "v6"}, |
| 25 |
[]imgspecv1.Platform{ |
| 26 |
{OS: "linux", Architecture: "arm", Variant: "v6"}, |
| 27 |
{OS: "linux", Architecture: "arm", Variant: "v5"}, |
| 28 |
{OS: "linux", Architecture: "arm", Variant: ""}, |
| 29 |
}, |
| 30 |
}, |
| 31 |
{ // ARM without variant |
| 32 |
types.SystemContext{ArchitectureChoice: "arm", OSChoice: "linux"}, |
| 33 |
[]imgspecv1.Platform{ |
| 34 |
{OS: "linux", Architecture: "arm", Variant: ""}, |
| 35 |
{OS: "linux", Architecture: "arm", Variant: "v8"}, |
| 36 |
{OS: "linux", Architecture: "arm", Variant: "v7"}, |
| 37 |
{OS: "linux", Architecture: "arm", Variant: "v6"}, |
| 38 |
{OS: "linux", Architecture: "arm", Variant: "v5"}, |
| 39 |
}, |
| 40 |
}, |
| 41 |
{ // ARM64 has a base variant |
| 42 |
types.SystemContext{ArchitectureChoice: "arm64", OSChoice: "linux"}, |
| 43 |
[]imgspecv1.Platform{ |
| 44 |
{OS: "linux", Architecture: "arm64", Variant: ""}, |
| 45 |
{OS: "linux", Architecture: "arm64", Variant: "v8"}, |
| 46 |
}, |
| 47 |
}, |
| 48 |
{ // Custom (completely unrecognized data) |
| 49 |
types.SystemContext{ArchitectureChoice: "armel", OSChoice: "freeBSD", VariantChoice: "custom"}, |
| 50 |
[]imgspecv1.Platform{ |
| 51 |
{OS: "freeBSD", Architecture: "armel", Variant: "custom"}, |
| 52 |
{OS: "freeBSD", Architecture: "armel", Variant: ""}, |
| 53 |
}, |
| 54 |
}, |
| 55 |
} { |
| 56 |
testName := fmt.Sprintf("%q/%q/%q", c.ctx.ArchitectureChoice, c.ctx.OSChoice, c.ctx.VariantChoice) |
| 57 |
platforms := WantedPlatforms(&c.ctx) |
| 58 |
assert.Equal(t, c.expected, platforms, testName) |
| 59 |
} |
| 60 |
} |