-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_test.go
79 lines (74 loc) · 2.08 KB
/
version_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
package common
import "testing"
func TestNodeVersion(t *testing.T) {
tests := []struct {
major, minor, patch uint64
err bool
v Version
}{
{0, 0, 0, false, 0},
{0, 10, 0, false, 10000},
{0, 10, 999, false, 10999},
{2, 0, 0, false, 2000000},
{3, 100, 36, false, 3100036},
{1000, 100, 36, true, 0},
{3, 2000, 36, true, 0},
{3, 100, 6000, true, 0},
}
for _, test := range tests {
ver, err := NewNodeVersion(test.major, test.minor, test.patch)
if err != nil {
if test.err {
t.Logf("major:%d minor:%d patch:%d error:%v check", test.major, test.minor, test.patch, err)
} else {
t.Fatalf("major:%d minor:%d patch:%d failed:%v", test.major, test.minor, test.patch, err)
}
} else {
if test.err {
t.Fatalf("major:%d minor:%d patch:%d should failed, but: %s", test.major, test.minor, test.patch, ver)
} else {
if ver != test.v {
t.Fatalf("major:%d minor:%d patch:%d should be %d but %d", test.major, test.minor, test.patch, test.v, ver)
} else {
if ver.Major() == test.major && ver.Minor() == test.minor && ver.Patch() == test.patch {
t.Logf("major:%d minor:%d patch:%d -> %s check", test.major, test.minor, test.patch, ver)
} else {
t.Fatalf("major:%d minor:%d patch:%d %s check versions failed", test.major, test.minor, test.patch, ver)
}
}
}
}
}
}
func TestVersionString(t *testing.T) {
tests := []struct {
input string
err bool
v Version
}{
{"7.2.6", false, 7002006},
{"7x.2.6", true, 0},
{"7009.2.6", true, 0},
{"7.5.0", false, 7005000},
}
for _, test := range tests {
ver, err := NewVersion(test.input)
if err != nil {
if test.err {
t.Logf("input:%s error:%v check", test.input, err)
} else {
t.Fatalf("input:%s failed: %v", test.input, err)
}
} else {
if test.err {
t.Fatalf("input:%s should error, but didn't, got: %s", test.input, ver)
} else {
if ver != test.v {
t.Fatalf("input:%s should be %d but got %d", test.input, test.v, ver)
} else {
t.Logf("input:%s is %d check", test.input, ver)
}
}
}
}
}