-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlist_test.go
More file actions
126 lines (113 loc) · 2.16 KB
/
list_test.go
File metadata and controls
126 lines (113 loc) · 2.16 KB
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
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)
}
}
}
func TestGetListWithTagInfo(t *testing.T) {
withInfo := `v1.0.0 2018-11-28 16:05:12 +0900 linyows
v1.0.1 2018-11-29 00:17:14 +0900 linyows
v1.1.0 2019-03-19 11:53:24 +0900 linyows`
want := `v1.0.0 2018-11-28 16:05:12 +0900 linyows
v1.0.1 2018-11-29 00:17:14 +0900 linyows
v1.1.0 2019-03-19 11:53:24 +0900 linyows`
tagCmder = MockedCmd{Out: withInfo}
l, err := GetList()
if err != nil {
t.Fatal(err)
}
if l.String() != want {
t.Errorf("List = %s; want %s", l, want)
}
}
func TestTagInfoFormat(t *testing.T) {
tests := []struct {
info *TagInfo
tagName string
want string
}{
{
&TagInfo{
TaggerDate: "2018-11-28 16:05:12 +0900",
TaggerName: "linyows",
},
"v1.0.0",
"v1.0.0\t2018-11-28 16:05:12 +0900\tlinyows",
},
{
&TagInfo{
TaggerDate: "",
TaggerName: "",
},
"v2.0.0",
"v2.0.0\t\t",
},
}
for i, tt := range tests {
got := tt.info.Format(tt.tagName)
if got != tt.want {
t.Errorf("test[%d]: Format = %s; want %s", i, got, tt.want)
}
}
}