-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvariant_test.go
172 lines (145 loc) · 4.42 KB
/
variant_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package cask
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewVariant(t *testing.T) {
// preparations
v := NewVariant()
// test
assert.IsType(t, Variant{}, *v)
assert.Empty(t, v.Version)
assert.Empty(t, v.SHA256)
assert.Nil(t, v.Appcast)
assert.Empty(t, v.URL)
assert.Len(t, v.Names, 0)
assert.Empty(t, v.Homepage)
assert.Len(t, v.Artifacts, 0)
assert.Equal(t, MacOSHighSierra, v.MinimumSupportedMacOS)
assert.Equal(t, MacOSHighSierra, v.MaximumSupportedMacOS)
}
func TestAddName(t *testing.T) {
// preparations
v := NewVariant()
// test
assert.Len(t, v.Names, 0)
v.AddName(NewName("test"))
assert.Len(t, v.Names, 1)
}
func TestAddArtifact(t *testing.T) {
// preparations
v := NewVariant()
// test
assert.Len(t, v.Artifacts, 0)
v.AddArtifact(NewArtifact(ArtifactApp, "test"))
assert.Len(t, v.Artifacts, 1)
}
func TestGetVersion(t *testing.T) {
// preparations
v := NewVariant()
v.Version = NewVersion("2.0.0")
// test
actual := v.GetVersion()
assert.IsType(t, &Version{}, v.Version)
assert.IsType(t, Version{}, actual)
assert.Equal(t, v.Version.Value, actual.Value)
}
func TestGetSHA256(t *testing.T) {
// preparations
v := NewVariant()
v.SHA256 = NewSHA256("92521fc3cbd964bdc9f584a991b89fddaa5754ed1cc96d6d42445338669c1305")
// test
actual := v.GetSHA256()
assert.IsType(t, &SHA256{}, v.SHA256)
assert.IsType(t, SHA256{}, actual)
assert.Equal(t, v.SHA256.Value, actual.Value)
}
func TestGetURL(t *testing.T) {
// preparations
v := NewVariant()
v.URL = NewURL("http://example.com/#{version}.dmg")
// test (without version)
actual := v.GetURL()
assert.IsType(t, &URL{}, v.URL)
assert.IsType(t, URL{}, actual)
assert.Equal(t, v.URL.Value, actual.Value)
// test (with version)
v.Version = NewVersion("2.0.0")
actual = v.GetURL()
assert.IsType(t, &URL{}, v.URL)
assert.IsType(t, URL{}, actual)
assert.Equal(t, "http://example.com/2.0.0.dmg", actual.Value)
}
func TestGetAppcast(t *testing.T) {
// preparations
v := NewVariant()
v.Appcast = NewAppcast(
"http://example.com/#{version}/appcast.xml",
"2ffedc4898df88e05a6e8f5519e11159d967153f75f8d4e8c9a0286d347ea1e1",
)
// test (without version)
actual := v.GetAppcast()
assert.IsType(t, &Appcast{}, v.Appcast)
assert.IsType(t, Appcast{}, actual)
assert.Equal(t, v.Appcast.URL, actual.URL)
// test (with version)
v.Version = NewVersion("2.0.0")
actual = v.GetAppcast()
assert.IsType(t, &Appcast{}, v.Appcast)
assert.IsType(t, Appcast{}, actual)
assert.Equal(t, "http://example.com/2.0.0/appcast.xml", actual.URL)
}
func TestGetNames(t *testing.T) {
// preparations
v := NewVariant()
v.Names = append(v.Names, NewName("Name"))
v.Names = append(v.Names, NewName("Name #{version}"))
// test (without version)
actual := v.GetNames()
assert.Len(t, actual, len(v.Names))
assert.IsType(t, []Name{}, actual)
assert.Equal(t, v.Names[0].Value, actual[0].Value)
assert.Equal(t, v.Names[1].Value, actual[1].Value)
// test (with version)
v.Version = NewVersion("2.0.0")
actual = v.GetNames()
assert.Len(t, actual, len(v.Names))
assert.IsType(t, []Name{}, actual)
assert.Equal(t, v.Names[0].Value, actual[0].Value)
assert.Equal(t, "Name 2.0.0", actual[1].Value)
}
func TestGetHomepage(t *testing.T) {
// preparations
v := NewVariant()
v.Homepage = NewHomepage("http://example.com/#{version}/")
// test (without version)
actual := v.GetHomepage()
assert.IsType(t, &Homepage{}, v.Homepage)
assert.IsType(t, Homepage{}, actual)
assert.Equal(t, v.Homepage.Value, actual.Value)
// test (with version)
v.Version = NewVersion("2.0.0")
actual = v.GetHomepage()
assert.IsType(t, &Homepage{}, v.Homepage)
assert.IsType(t, Homepage{}, actual)
assert.Equal(t, "http://example.com/2.0.0/", actual.Value)
}
func TestGetArtifacts(t *testing.T) {
// preparations
v := NewVariant()
v.Artifacts = append(v.Artifacts, NewArtifact(ArtifactApp, "Test.app"))
v.Artifacts = append(v.Artifacts, NewArtifact(ArtifactApp, "Test #{version}.app"))
// test (without version)
actual := v.GetArtifacts()
assert.Len(t, actual, len(v.Artifacts))
assert.IsType(t, []Artifact{}, actual)
assert.Equal(t, v.Artifacts[0].Value, actual[0].Value)
assert.Equal(t, v.Artifacts[1].Value, actual[1].Value)
// test (with version)
v.Version = NewVersion("2.0.0")
actual = v.GetArtifacts()
assert.Len(t, actual, len(v.Artifacts))
assert.IsType(t, []Artifact{}, actual)
assert.Equal(t, v.Artifacts[0].Value, actual[0].Value)
assert.Equal(t, "Test 2.0.0.app", actual[1].Value)
}