-
Notifications
You must be signed in to change notification settings - Fork 4
/
list_test.go
75 lines (67 loc) · 1.16 KB
/
list_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
package semv
import (
"testing"
"github.com/blang/semver"
)
func TestGetList(t *testing.T) {
want := `v2.3.4-rc.2
v8.8.8
v12.0.1
v12.3.0-alpha
v12.3.0-alpha.0
v12.3.0-alpha.1
v12.3.0-alpha.1.beta
v12.3.0-beta
v12.3.0-beta.5
v12.3.0-rc
v12.344.0+20130313144700
v12.345.66
v12.345.67
v13.0.0-alpha.0`
tests := []struct {
out string
want string
}{
{mixed, want},
{empty, ""},
}
for i, tt := range tests {
tagCmder = MockedCmd{Out: tt.out}
l, err := GetList()
if err != nil {
t.Fatal(err)
}
if l.String() != tt.want {
t.Errorf("test[%d]: List = %s; want %s", i, l, tt.want)
}
}
}
func TestFindSimilar(t *testing.T) {
out := `v1.0.0
v1.0.1
v1.0.2-rc.0`
tests := []struct {
out string
find string
want string
}{
{out, "v1.0.2", "v1.0.2-rc.0"},
{out, "v1.0.3", ""},
{"", "v1.0.3", ""},
}
for i, tt := range tests {
tagCmder = MockedCmd{Out: tt.out}
l, err := GetList()
if err != nil {
t.Fatal(err)
}
v, err := semver.ParseTolerant(tt.find)
if err != nil {
t.Fatal(err)
}
semv := l.FindSimilar(v)
if semv.String() != tt.want {
t.Errorf("test[%d]: semver.Version = %s; want %s", i, semv, tt.want)
}
}
}