This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
version_test.go
106 lines (96 loc) · 2.46 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
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
package gps
import "testing"
func TestVersionSorts(t *testing.T) {
rev := Revision("flooboofoobooo")
v1 := NewBranch("master").Is(rev)
v2 := NewBranch("test").Is(rev)
v3 := NewVersion("1.0.0").Is(rev)
v4 := NewVersion("1.0.1")
v5 := NewVersion("v2.0.5")
v6 := NewVersion("2.0.5.2")
v7 := newDefaultBranch("unwrapped")
v8 := NewVersion("20.0.5.2")
v9 := NewVersion("v1.5.5-beta.4")
v10 := NewVersion("v3.0.1-alpha.1")
start := []Version{
v1,
v2,
v3,
v4,
v5,
v6,
v7,
v8,
v9,
v10,
rev,
}
down := make([]Version, len(start))
copy(down, start)
up := make([]Version, len(start))
copy(up, start)
edown := []Version{
v3, v4, v5, // semvers
v9, v10, // prerelease semver
v7, v1, v2, // floating/branches
v6, v8, // plain versions
rev, // revs
}
eup := []Version{
v5, v4, v3, // semvers
v10, v9, // prerelease semver
v7, v1, v2, // floating/branches
v6, v8, // plain versions
rev, // revs
}
SortForUpgrade(up)
var wrong []int
for k, v := range up {
if eup[k] != v {
wrong = append(wrong, k)
t.Errorf("Expected version %s in position %v on upgrade sort, but got %s", eup[k], k, v)
}
}
if len(wrong) > 0 {
// Just helps with readability a bit
t.Errorf("Upgrade sort positions with wrong versions: %v", wrong)
}
SortForDowngrade(down)
wrong = wrong[:0]
for k, v := range down {
if edown[k] != v {
wrong = append(wrong, k)
t.Errorf("Expected version %s in position %v on downgrade sort, but got %s", edown[k], k, v)
}
}
if len(wrong) > 0 {
// Just helps with readability a bit
t.Errorf("Downgrade sort positions with wrong versions: %v", wrong)
}
// Now make sure we sort back the other way correctly...just because
SortForUpgrade(down)
wrong = wrong[:0]
for k, v := range down {
if eup[k] != v {
wrong = append(wrong, k)
t.Errorf("Expected version %s in position %v on down-then-upgrade sort, but got %s", eup[k], k, v)
}
}
if len(wrong) > 0 {
// Just helps with readability a bit
t.Errorf("Down-then-upgrade sort positions with wrong versions: %v", wrong)
}
// Now make sure we sort back the other way correctly...just because
SortForDowngrade(up)
wrong = wrong[:0]
for k, v := range up {
if edown[k] != v {
wrong = append(wrong, k)
t.Errorf("Expected version %s in position %v on up-then-downgrade sort, but got %s", edown[k], k, v)
}
}
if len(wrong) > 0 {
// Just helps with readability a bit
t.Errorf("Up-then-downgrade sort positions with wrong versions: %v", wrong)
}
}