-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_test.go
122 lines (114 loc) · 2.38 KB
/
parse_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
package version
import (
"testing"
semver "github.com/Masterminds/semver"
)
func TestParseVersionError(t *testing.T) {
testCases := []struct {
TestName string
VersionNumber string
Expected error
}{
{
TestName: "Invalid Version",
VersionNumber: "N/A",
Expected: &VersionError{
message: "Parsing Version",
err: semver.ErrInvalidSemVer,
},
}}
for _, testCase := range testCases {
tc := testCase
t.Run(tc.TestName, func(t *testing.T) {
_, err := parseVersion(tc.VersionNumber)
if err.Error() != tc.Expected.Error() {
t.Errorf("Expected: %s Got: %s", tc.Expected, err)
}
})
}
}
func TestParseVersion(t *testing.T) {
testCases := []struct {
TestName string
VersionNumber string
Major int64
Minor int64
Patch int64
}{
{
"MajorOnly",
"1",
1,
0,
0,
},
{
"Major.MinorOnly",
"1.1",
1,
1,
0,
},
{
"Major.Minor.Patch",
"1.2.3",
1,
2,
3,
},
{
"Major.Minor.Patch",
"1.2.0",
1,
2,
0,
},
}
for _, testCase := range testCases {
version, _ := parseVersion(testCase.VersionNumber)
major, minor, patch := version.Major(), version.Minor(), version.Patch()
if major != testCase.Major {
t.Errorf("TestName: %s - Found Major versions are not equal (expected %d but got %d)", testCase.TestName, testCase.Major, major)
}
if minor != testCase.Minor {
t.Errorf("TestName: %s - Found Minor versions are not equal (expected %d but got %d)", testCase.TestName, testCase.Minor, minor)
}
if patch != testCase.Patch {
t.Errorf("TestName: %s - Found Patch versions are not equal (expected %d but got %d)", testCase.TestName, testCase.Patch, patch)
}
}
}
func TestUpgradeAvailable(t *testing.T) {
testCases := []struct {
TestName string
VersionNumber string
remoteVersion string
Expected bool
}{
{
"Version is the same.",
"1.0.0",
"1.0.0",
false,
},
{
"Version is less than Remote Version.",
"0.0.0",
"1.0.0",
true,
},
{
"Version is greater than Remote Version.",
"1.0.0",
"0.0.0",
false,
},
}
for _, testCase := range testCases {
BuildVersion = testCase.VersionNumber
available, _ := UpgradeAvailable(testCase.remoteVersion)
if available != testCase.Expected {
t.Errorf("TestName: %s - Expected: %t Got: %t", testCase.TestName, testCase.Expected, available)
}
}
}