Skip to content

Commit 66a3f2c

Browse files
committed
Add platforms.Only test
This adds a test for `platforms.Only` (previously untested, as far as I can tell). Signed-off-by: Tianon Gravi <[email protected]>
1 parent 178e9a1 commit 66a3f2c

1 file changed

Lines changed: 208 additions & 0 deletions

File tree

platforms/compare_test.go

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package platforms
18+
19+
import (
20+
"testing"
21+
)
22+
23+
func TestOnly(t *testing.T) {
24+
for _, tc := range []struct {
25+
platform string
26+
matches map[bool][]string
27+
}{
28+
{
29+
platform: "linux/amd64",
30+
matches: map[bool][]string{
31+
true: {
32+
"linux/amd64",
33+
},
34+
false: {
35+
"linux/386",
36+
"linux/arm/v7",
37+
"linux/arm64",
38+
"windows/amd64",
39+
"windows/arm",
40+
},
41+
},
42+
},
43+
{
44+
platform: "linux/386",
45+
matches: map[bool][]string{
46+
true: {
47+
"linux/386",
48+
},
49+
false: {
50+
"linux/amd64",
51+
"linux/arm/v7",
52+
"linux/arm64",
53+
"windows/amd64",
54+
"windows/arm",
55+
},
56+
},
57+
},
58+
{
59+
platform: "windows/amd64",
60+
matches: map[bool][]string{
61+
true: {"windows/amd64"},
62+
false: {
63+
"linux/amd64",
64+
"linux/arm/v7",
65+
"linux/arm64",
66+
"windows/arm",
67+
},
68+
},
69+
},
70+
{
71+
platform: "linux/arm/v8",
72+
matches: map[bool][]string{
73+
true: {
74+
"linux/arm",
75+
"linux/arm/v5",
76+
"linux/arm/v6",
77+
"linux/arm/v7",
78+
"linux/arm/v8",
79+
},
80+
false: {
81+
"linux/amd64",
82+
"linux/arm/v4",
83+
"linux/arm64",
84+
"windows/amd64",
85+
"windows/arm",
86+
},
87+
},
88+
},
89+
{
90+
platform: "linux/arm/v7",
91+
matches: map[bool][]string{
92+
true: {
93+
"linux/arm",
94+
"linux/arm/v5",
95+
"linux/arm/v6",
96+
"linux/arm/v7",
97+
},
98+
false: {
99+
"linux/amd64",
100+
"linux/arm/v4",
101+
"linux/arm/v8",
102+
"linux/arm64",
103+
"windows/amd64",
104+
"windows/arm",
105+
},
106+
},
107+
},
108+
{
109+
platform: "linux/arm/v6",
110+
matches: map[bool][]string{
111+
true: {
112+
"linux/arm/v5",
113+
"linux/arm/v6",
114+
},
115+
false: {
116+
"linux/amd64",
117+
"linux/arm",
118+
"linux/arm/v4",
119+
"linux/arm/v7",
120+
"linux/arm/v8",
121+
"linux/arm64",
122+
"windows/amd64",
123+
"windows/arm",
124+
},
125+
},
126+
},
127+
{
128+
platform: "linux/arm/v5",
129+
matches: map[bool][]string{
130+
true: {
131+
"linux/arm/v5",
132+
},
133+
false: {
134+
"linux/amd64",
135+
"linux/arm",
136+
"linux/arm/v4",
137+
"linux/arm/v6",
138+
"linux/arm/v7",
139+
"linux/arm/v8",
140+
"linux/arm64",
141+
"windows/amd64",
142+
"windows/arm",
143+
},
144+
},
145+
},
146+
{
147+
platform: "linux/arm/v4",
148+
matches: map[bool][]string{
149+
true: {
150+
"linux/arm/v4",
151+
},
152+
false: {
153+
"linux/amd64",
154+
"linux/arm",
155+
"linux/arm/v5",
156+
"linux/arm/v6",
157+
"linux/arm/v7",
158+
"linux/arm/v8",
159+
"linux/arm64",
160+
"windows/amd64",
161+
"windows/arm",
162+
},
163+
},
164+
},
165+
{
166+
platform: "linux/arm64",
167+
matches: map[bool][]string{
168+
true: {
169+
"linux/arm64",
170+
"linux/arm64/v8",
171+
},
172+
false: {
173+
"linux/amd64",
174+
"linux/arm",
175+
"linux/arm/v4",
176+
"linux/arm/v5",
177+
"linux/arm/v6",
178+
"linux/arm/v7",
179+
"linux/arm/v8",
180+
"linux/arm/v9",
181+
"linux/arm64/v9",
182+
"windows/amd64",
183+
"windows/arm",
184+
},
185+
},
186+
},
187+
} {
188+
testcase := tc
189+
t.Run(testcase.platform, func(t *testing.T) {
190+
p, err := Parse(testcase.platform)
191+
if err != nil {
192+
t.Fatal(err)
193+
}
194+
m := Only(p)
195+
for shouldMatch, platforms := range testcase.matches {
196+
for _, matchPlatform := range platforms {
197+
mp, err := Parse(matchPlatform)
198+
if err != nil {
199+
t.Fatal(err)
200+
}
201+
if match := m.Match(mp); shouldMatch != match {
202+
t.Errorf("Only(%q).Match(%q) should return %v, but returns %v", testcase.platform, matchPlatform, shouldMatch, match)
203+
}
204+
}
205+
}
206+
})
207+
}
208+
}

0 commit comments

Comments
 (0)