1717package platforms
1818
1919import (
20- "fmt"
2120 "reflect"
2221 "runtime"
2322 "testing"
@@ -35,6 +34,7 @@ func TestParseSelector(t *testing.T) {
3534 skip bool
3635 input string
3736 expected specs.Platform
37+ matches []specs.Platform
3838 formatted string
3939 }{
4040 // While wildcards are a valid use case for platform selection,
@@ -66,8 +66,72 @@ func TestParseSelector(t *testing.T) {
6666 OS : "*" ,
6767 Architecture : "arm64" ,
6868 },
69+ matches : []specs.Platform {
70+ {
71+ OS : "*" ,
72+ Architecture : "aarch64" ,
73+ },
74+ {
75+ OS : "*" ,
76+ Architecture : "aarch64" ,
77+ Variant : "v8" ,
78+ },
79+ {
80+ OS : "*" ,
81+ Architecture : "arm64" ,
82+ Variant : "v8" ,
83+ },
84+ },
6985 formatted : "*/arm64" ,
7086 },
87+ {
88+ input : "linux/arm64" ,
89+ expected : specs.Platform {
90+ OS : "linux" ,
91+ Architecture : "arm64" ,
92+ },
93+ matches : []specs.Platform {
94+ {
95+ OS : "linux" ,
96+ Architecture : "aarch64" ,
97+ },
98+ {
99+ OS : "linux" ,
100+ Architecture : "aarch64" ,
101+ Variant : "v8" ,
102+ },
103+ {
104+ OS : "linux" ,
105+ Architecture : "arm64" ,
106+ Variant : "v8" ,
107+ },
108+ },
109+ formatted : "linux/arm64" ,
110+ },
111+ {
112+ input : "linux/arm64/v8" ,
113+ expected : specs.Platform {
114+ OS : "linux" ,
115+ Architecture : "arm64" ,
116+ Variant : "v8" ,
117+ },
118+ matches : []specs.Platform {
119+ {
120+ OS : "linux" ,
121+ Architecture : "aarch64" ,
122+ },
123+ {
124+ OS : "linux" ,
125+ Architecture : "aarch64" ,
126+ Variant : "v8" ,
127+ },
128+ {
129+ OS : "linux" ,
130+ Architecture : "arm64" ,
131+ },
132+ },
133+ formatted : "linux/arm64/v8" ,
134+ },
71135 {
72136 // NOTE(stevvooe): In this case, the consumer can assume this is v7
73137 // but we leave the variant blank. This will represent the vast
@@ -77,6 +141,22 @@ func TestParseSelector(t *testing.T) {
77141 OS : "linux" ,
78142 Architecture : "arm" ,
79143 },
144+ matches : []specs.Platform {
145+ {
146+ OS : "linux" ,
147+ Architecture : "arm" ,
148+ Variant : "v7" ,
149+ },
150+ {
151+ OS : "linux" ,
152+ Architecture : "armhf" ,
153+ },
154+ {
155+ OS : "linux" ,
156+ Architecture : "arm" ,
157+ Variant : "7" ,
158+ },
159+ },
80160 formatted : "linux/arm" ,
81161 },
82162 {
@@ -86,6 +166,12 @@ func TestParseSelector(t *testing.T) {
86166 Architecture : "arm" ,
87167 Variant : "v6" ,
88168 },
169+ matches : []specs.Platform {
170+ {
171+ OS : "linux" ,
172+ Architecture : "armel" ,
173+ },
174+ },
89175 formatted : "linux/arm/v6" ,
90176 },
91177 {
@@ -95,6 +181,16 @@ func TestParseSelector(t *testing.T) {
95181 Architecture : "arm" ,
96182 Variant : "v7" ,
97183 },
184+ matches : []specs.Platform {
185+ {
186+ OS : "linux" ,
187+ Architecture : "arm" ,
188+ },
189+ {
190+ OS : "linux" ,
191+ Architecture : "armhf" ,
192+ },
193+ },
98194 formatted : "linux/arm/v7" ,
99195 },
100196 {
@@ -204,11 +300,12 @@ func TestParseSelector(t *testing.T) {
204300
205301 // ensure that match works on the input to the output.
206302 if ok := m .Match (testcase .expected ); ! ok {
207- t .Fatalf ("expected specifier %q matches %v" , testcase .input , testcase .expected )
303+ t .Fatalf ("expected specifier %q matches %# v" , testcase .input , testcase .expected )
208304 }
209-
210- if fmt .Sprint (m ) != testcase .formatted {
211- t .Fatalf ("unexpected matcher string: %q != %q" , fmt .Sprint (m ), testcase .formatted )
305+ for _ , mc := range testcase .matches {
306+ if ok := m .Match (mc ); ! ok {
307+ t .Fatalf ("expected specifier %q matches %#v" , testcase .input , mc )
308+ }
212309 }
213310
214311 formatted := Format (p )
0 commit comments