4
4
"testing"
5
5
6
6
"github.com/docker-library/bashbrew/architecture"
7
+
8
+ ocispec "github.com/opencontainers/image-spec/specs-go/v1"
7
9
)
8
10
9
11
func TestString (t * testing.T ) {
@@ -21,3 +23,45 @@ func TestString(t *testing.T) {
21
23
})
22
24
}
23
25
}
26
+
27
+ func TestIs (t * testing.T ) {
28
+ tests := map [bool ][][2 ]architecture.OCIPlatform {
29
+ true : {
30
+ {architecture .SupportedArches ["amd64" ], architecture .SupportedArches ["amd64" ]},
31
+ {architecture .SupportedArches ["arm32v5" ], architecture .SupportedArches ["arm32v5" ]},
32
+ {architecture .SupportedArches ["arm32v6" ], architecture .SupportedArches ["arm32v6" ]},
33
+ {architecture .SupportedArches ["arm32v7" ], architecture .SupportedArches ["arm32v7" ]},
34
+ {architecture .SupportedArches ["arm64v8" ], architecture.OCIPlatform {OS : "linux" , Architecture : "arm64" , Variant : "v8" }},
35
+ {architecture .SupportedArches ["windows-amd64" ], architecture.OCIPlatform {OS : "windows" , Architecture : "amd64" , OSVersion : "1.2.3.4" }},
36
+ },
37
+ false : {
38
+ {architecture .SupportedArches ["amd64" ], architecture.OCIPlatform {OS : "linux" , Architecture : "amd64" , Variant : "v4" }},
39
+ {architecture .SupportedArches ["amd64" ], architecture .SupportedArches ["arm64v8" ]},
40
+ {architecture .SupportedArches ["amd64" ], architecture .SupportedArches ["i386" ]},
41
+ {architecture .SupportedArches ["amd64" ], architecture .SupportedArches ["windows-amd64" ]},
42
+ {architecture .SupportedArches ["arm32v7" ], architecture .SupportedArches ["arm32v6" ]},
43
+ {architecture .SupportedArches ["arm32v7" ], architecture .SupportedArches ["arm64v8" ]},
44
+ {architecture .SupportedArches ["arm64v8" ], architecture.OCIPlatform {OS : "linux" , Architecture : "arm64" , Variant : "v9" }},
45
+ },
46
+ }
47
+ for expected , test := range tests {
48
+ for _ , platforms := range test {
49
+ t .Run (platforms [0 ].String ()+ " vs " + platforms [1 ].String (), func (t * testing.T ) {
50
+ if got := platforms [0 ].Is (platforms [1 ]); got != expected {
51
+ t .Errorf ("expected %v; got %v" , expected , got )
52
+ }
53
+ })
54
+ }
55
+ }
56
+ }
57
+
58
+ func TestNormalize (t * testing.T ) {
59
+ for arch , expected := range architecture .SupportedArches {
60
+ t .Run (arch , func (t * testing.T ) {
61
+ normal := architecture .OCIPlatform (architecture .Normalize (ocispec .Platform (expected )))
62
+ if ! expected .Is (normal ) {
63
+ t .Errorf ("expected %#v; got %#v" , expected , normal )
64
+ }
65
+ })
66
+ }
67
+ }
0 commit comments