-
Notifications
You must be signed in to change notification settings - Fork 2
/
platforms_test.go
117 lines (89 loc) · 2.36 KB
/
platforms_test.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"fmt"
"sort"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
func ExampleNewPlatformBuilder() {
plb, _ := NewPlatformBuilder()
plb = plb.
WithOS(OS("windows")).
WithoutPlatform(Platform{OS("windows"), Arch("amd64")}).
WithPlatform(Platform{OS("plan9"), Arch("amd64")})
pl := plb.Build()
sort.SliceStable(pl, func(i, j int) bool {
return lessPlatforms(pl[i], pl[j])
})
fmt.Println(pl)
// Output:
// [{plan9 amd64} {windows 386}]
}
func TestWithOS(t *testing.T) {
plb, _ := NewPlatformBuilder()
plb = plb.WithOS(OS("windows"))
pl := plb.Build()
expected := defaultWindows()
if diff := cmp.Diff(expected, pl, cmpopts.SortSlices(lessPlatforms)); diff != "" {
t.Errorf("manifest differs. (-got +want):\n%s", diff)
}
}
func TestWithoutOS(t *testing.T) {
plb, _ := NewPlatformBuilder()
plb = plb.
WithPlatform(
Platform{OS("windows"), Arch("amd64")},
).
WithPlatform(
Platform{OS("plan9"), Arch("amd64")},
).
WithoutOS(OS("windows"))
pl := plb.Build()
expected := []Platform{{OS("plan9"), Arch("amd64")}}
if diff := cmp.Diff(expected, pl, cmpopts.SortSlices(lessPlatforms)); diff != "" {
t.Errorf("manifest differs. (-got +want):\n%s", diff)
}
}
func TestWithPlatform(t *testing.T) {
plb, _ := NewPlatformBuilder()
plb = plb.WithPlatform(Platform{OS("windows"), Arch("arm64")})
pl := plb.Build()
expected := []Platform{{OS("windows"), Arch("arm64")}}
if diff := cmp.Diff(expected, pl, cmpopts.SortSlices(lessPlatforms)); diff != "" {
t.Errorf("manifest differs. (-got +want):\n%s", diff)
}
}
func TestWithoutPlaform(t *testing.T) {
plb, _ := NewPlatformBuilder()
plb = plb.
WithOS(OS("windows")).
WithOS(OS("plan9")).
WithoutPlatform(Platform{OS("windows"), Arch("386")})
pl := plb.Build()
expected := []Platform{
{OS("windows"), Arch("amd64")},
{OS("plan9"), Arch("386")},
{OS("plan9"), Arch("amd64")},
}
if diff := cmp.Diff(expected, pl, cmpopts.SortSlices(lessPlatforms)); diff != "" {
t.Errorf("manifest differs. (-got +want):\n%s", diff)
}
}
func TestWithDefaults(t *testing.T) {
plb, _ := NewPlatformBuilder()
plb = plb.WithDefaults()
pl := plb.Build()
if len(pl) == 0 {
t.Errorf("expected more defaults!")
}
}
func lessPlatforms(x, y Platform) bool {
if x.OS < y.OS {
return true
}
if x.OS > y.OS {
return false
}
return x.Arch < y.Arch
}