-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformat_test.go
111 lines (92 loc) · 2.56 KB
/
format_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
package main
import (
"strings"
"testing"
"time"
)
func TestGetNextVersion(t *testing.T) {
tag, _ := GetNextVersion("v3.1.5")
expected := "v3.1.6"
if tag != expected {
t.Errorf("Output=%q, Expected=%q", tag, expected)
}
}
func TestGetNextVersion_Semantic(t *testing.T) {
tag, _ := GetNextVersion("4.2.6")
expected := "4.2.7"
if tag != expected {
t.Errorf("Output=%q, Expected=%q", tag, expected)
}
}
func TestGetNextVersion_SemanticError(t *testing.T) {
_, err := GetNextVersion("4.2.semantic")
expected := "invalid syntax"
if !strings.Contains(err.Error(), expected) {
t.Errorf("Output=%q, Expected=%q", err.Error(), expected)
}
}
func TestGetNextVersion_Date(t *testing.T) {
tag, _ := GetNextVersion("20180525.1")
const layout = "20060102"
today := time.Now().Format(layout)
expected := today + ".1"
if tag != expected {
t.Errorf("Output=%q, Expected=%q", tag, expected)
}
}
func TestGetNextVersion_DatePlus(t *testing.T) {
const layout = "20060102"
today := time.Now().Format(layout)
tag, _ := GetNextVersion(today + ".1")
expected := today + ".2"
if tag != expected {
t.Errorf("Output=%q, Expected=%q", tag, expected)
}
}
func TestGetNextVersion_DateWithPrefix(t *testing.T) {
const prefix = "release_"
tag, _ := GetNextVersion(prefix + "20180525.1")
const layout = "20060102"
today := time.Now().Format(layout)
expected := prefix + today + ".1"
if tag != expected {
t.Errorf("Output=%q, Expected=%q", tag, expected)
}
}
func TestGetNextVersion_DatePlusWithPrefix(t *testing.T) {
const prefix = "release_"
const layout = "20060102"
today := time.Now().Format(layout)
tag, _ := GetNextVersion(prefix + today + ".1")
expected := prefix + today + ".2"
if tag != expected {
t.Errorf("Output=%q, Expected=%q", tag, expected)
}
}
func TestGetNextVersion_DateError(t *testing.T) {
const layout = "20060102"
today := time.Now().Format(layout)
_, err := GetNextVersion(today + ".date")
expected := "invalid syntax"
if !strings.Contains(err.Error(), expected) {
t.Errorf("Output=%q, Expected=%q", err.Error(), expected)
}
}
func TestGetNextVersion_EmptyTag(t *testing.T) {
tag, _ := GetNextVersion("")
expected := "v1.0.0"
if tag != expected {
t.Errorf("Output=%q, Expected=%q", tag, expected)
}
}
func TestGetReleaseNote(t *testing.T) {
list := "- itosho: initial commit\n"
list = list + "- itosho: fix bug"
note := GetReleaseNote("20180525.1", list)
expected := "Release 20180525.1\n\n"
expected = expected + "## 20180525.1\n"
expected = expected + list
if note != expected {
t.Errorf("Output=%q, Expected=%q", note, expected)
}
}