-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_test.go
123 lines (114 loc) · 3.23 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"testing"
)
func TestVersion_Update_BadString(t *testing.T) {
v := Version{}
config := CreateConfig()
err := v.Update("empty", config)
if v.Major != 0 || v.Minor != 0 || v.Patch != 0 {
t.Fatalf(
"Unexpected version value. Got %d.%d.%d, expected 0.0.0\n",
v.Major, v.Minor, v.Patch,
)
}
if err != nil {
t.Fatalf("Got unexpected error: %s\n", err.Error())
}
}
func TestVersion_Update_IncreaseMajor(t *testing.T) {
v := Version{Major: 1, Minor: 1, Patch: 1}
config := CreateConfig()
err := v.Update(":major: Commit", config)
if v.Major != 2 || v.Minor != 0 || v.Patch != 0 {
t.Fatalf(
"Unexpected version value. Got %d.%d.%d, expected 2.0.0\n",
v.Major, v.Minor, v.Patch,
)
}
if err != nil {
t.Fatalf("Got unexpected error: %s\n", err.Error())
}
}
func TestVersion_Update_IncreaseMinor(t *testing.T) {
v := Version{Major: 1, Minor: 1, Patch: 1}
config := CreateConfig()
err := v.Update(":minor: Commit", config)
if v.Major != 1 || v.Minor != 2 || v.Patch != 0 {
t.Fatalf(
"Unexpected version value. Got %d.%d.%d, expected 1.2.0\n",
v.Major, v.Minor, v.Patch,
)
}
if err != nil {
t.Fatalf("Got unexpected error: %s\n", err.Error())
}
}
func TestVersion_Update_IncreasePatch(t *testing.T) {
v := Version{Major: 1, Minor: 1, Patch: 1}
config := CreateConfig()
err := v.Update(":patch: Commit", config)
if v.Major != 1 || v.Minor != 1 || v.Patch != 2 {
t.Fatalf(
"Unexpected version value. Got %d.%d.%d, expected 1.1.2\n",
v.Major, v.Minor, v.Patch,
)
}
if err != nil {
t.Fatalf("Got unexpected error: %s\n", err.Error())
}
}
func TestVersion_Update_IncreasePatchP(t *testing.T) {
v := Version{Major: 1, Minor: 1, Patch: 1}
config := CreateConfig()
err := v.Update(":p: Commit", config)
if v.Major != 1 || v.Minor != 1 || v.Patch != 2 {
t.Fatalf(
"Unexpected version value. Got %d.%d.%d, expected 1.1.2\n",
v.Major, v.Minor, v.Patch,
)
}
if err != nil {
t.Fatalf("Got unexpected error: %s\n", err.Error())
}
}
func TestVersion_Update_IncreasePatchPMajorMultiple(t *testing.T) {
v := Version{Major: 1, Minor: 1, Patch: 1}
config := CreateConfig()
err := v.Update(":major: :minor: :patch: Commit", config)
if v.Major != 2 || v.Minor != 0 || v.Patch != 0 {
t.Fatalf(
"Unexpected version value. Got %d.%d.%d, expected 2.0.0\n",
v.Major, v.Minor, v.Patch,
)
}
if err != nil {
t.Fatalf("Got unexpected error: %s\n", err.Error())
}
}
func TestVersion_Update_Checkpoint(t *testing.T) {
v := Version{Major: 1, Minor: 1, Patch: 1}
config := CreateConfig()
err := v.Update(fmt.Sprintf("%s%s%s", checkpointPrefix, "3.2.1", checkpointSuffix), config)
if v.Major != 3 || v.Minor != 2 || v.Patch != 1 {
t.Fatalf(
"Unexpected version value. Got %d.%d.%d, expected 3.2.1\n",
v.Major, v.Minor, v.Patch,
)
}
if err != nil {
t.Fatalf("Got unexpected error: %s\n", err.Error())
}
}
func TestVersion_Update_CheckpointBadVersion(t *testing.T) {
v := Version{Major: 1, Minor: 1, Patch: 1}
config := CreateConfig()
err := v.Update(fmt.Sprintf("%s%s%s", checkpointPrefix, "boom", checkpointSuffix), config)
if err == nil {
t.Fatalf("Got no error\n")
}
if err.Error() != "Not valid checkpoint: boom" {
t.Fatalf("Got unexpected error: %s\n", err.Error())
}
}