forked from jenkins-x-plugins/jx-release-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
219 lines (157 loc) · 4.94 KB
/
main_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package main
import (
"context"
"testing"
"github.com/jenkins-x/jx-release-version/adapters"
"github.com/jenkins-x/jx-release-version/domain"
"github.com/jenkins-x/jx-release-version/mocks"
"github.com/stretchr/testify/assert"
)
func TestMakefile(t *testing.T) {
c := config{
dir: "test-resources/make",
}
v, err := getVersion(c)
assert.NoError(t, err)
assert.Equal(t, "1.2.0-SNAPSHOT", v, "error with getVersion for a Makefile")
}
func TestAutomakefile(t *testing.T) {
c := config{
dir: "test-resources/automake",
}
v, err := getVersion(c)
assert.NoError(t, err)
assert.Equal(t, "1.2.0-SNAPSHOT", v, "error with getVersion for a configure.ac")
}
func TestCMakefile(t *testing.T) {
c := config{
dir: "test-resources/cmake",
}
v, err := getVersion(c)
assert.NoError(t, err)
assert.Equal(t, "1.2.0-SNAPSHOT", v, "error with getVersion for a CMakeLists.txt")
}
func TestPomXML(t *testing.T) {
c := config{
dir: "test-resources/java",
}
v, err := getVersion(c)
assert.NoError(t, err)
assert.Equal(t, "1.0-SNAPSHOT", v, "error with getVersion for a pom.xml")
}
func TestPackageJSON(t *testing.T) {
c := config{
dir: "test-resources/package",
}
v, err := getVersion(c)
assert.NoError(t, err)
assert.Equal(t, "1.2.3", v, "error with getVersion for a package.json")
}
// TODO enable this. It seems that meta-pipeline is bumping the version of the Chart.yaml
// when the release pipeline is running, this is causing this test to fail.
/*
func TestChart(t *testing.T) {
c := config{
dir: "test-resources/helm",
}
v, err := getVersion(c)
assert.NoError(t, err)
assert.Equal(t, "0.0.1-SNAPSHOT", v, "error with getVersion for a Chart.yaml")
}
*/
func TestSetupPyStandard(t *testing.T) {
c := config{
dir: "test-resources/python/standard",
}
v, err := getVersion(c)
assert.NoError(t, err)
assert.Equal(t, "4.5.6", v, "error with getVersion for a setup.py")
}
func TestSetupPyNested(t *testing.T) {
c := config{
dir: "test-resources/python/nested",
}
v, err := getVersion(c)
assert.NoError(t, err)
assert.Equal(t, "4.5.6", v, "error with getVersion for a setup.py")
}
func TestSetupPyOneLine(t *testing.T) {
c := config{
dir: "test-resources/python/one_line",
}
v, err := getVersion(c)
assert.NoError(t, err)
assert.Equal(t, "4.5.6", v, "error with getVersion for a setup.py")
}
func TestGetGitTag(t *testing.T) {
c := config{
ghOwner: "jenkins-x",
ghRepository: "jx-release-version",
}
gitHubClient := adapters.NewGitHubClient(c.debug)
expectedVersion, err := getLatestTag(c, gitHubClient)
assert.NoError(t, err)
c = config{}
v, err := getLatestTag(c, gitHubClient)
assert.NoError(t, err)
assert.Equal(t, expectedVersion, v, "error with getLatestTag for a Makefile")
}
func TestGetNewVersionFromTagCurrentRepo(t *testing.T) {
c := config{
dryrun: false,
dir: "test-resources/make",
}
tags := createTags()
mockClient := &mocks.GitClient{}
mockClient.On("ListTags", context.Background(), c.ghOwner, c.ghRepository).Return(tags, nil)
v, err := getNewVersionFromTag(c, mockClient)
assert.NoError(t, err)
assert.Equal(t, "1.2.0", v, "error bumping a patch version")
}
func TestGetNewMinorVersionFromGitHubTag(t *testing.T) {
c := config{
ghOwner: "rawlingsj",
ghRepository: "semver-release-version",
minor: true,
}
tags := createTags()
mockClient := &mocks.GitClient{}
mockClient.On("ListTags", context.Background(), c.ghOwner, c.ghRepository).Return(tags, nil)
v, err := getNewVersionFromTag(c, mockClient)
assert.NoError(t, err)
assert.Equal(t, "1.1.0", v, "error bumping a minor version")
}
func TestGetNewPatchVersionFromGitHubTag(t *testing.T) {
c := config{
ghOwner: "rawlingsj",
ghRepository: "semver-release-version",
}
tags := createTags()
mockClient := &mocks.GitClient{}
mockClient.On("ListTags", context.Background(), c.ghOwner, c.ghRepository).Return(tags, nil)
v, err := getNewVersionFromTag(c, mockClient)
assert.NoError(t, err)
assert.Equal(t, "1.0.18", v, "error bumping a patch version")
}
func createTags() []domain.Tag {
var tags []domain.Tag
tags = append(tags, domain.Tag{Name: "v1.0.0"})
tags = append(tags, domain.Tag{Name: "v1.0.1"})
tags = append(tags, domain.Tag{Name: "v1.0.10"})
tags = append(tags, domain.Tag{Name: "v1.0.11"})
tags = append(tags, domain.Tag{Name: "v1.0.12"})
tags = append(tags, domain.Tag{Name: "v1.0.13"})
tags = append(tags, domain.Tag{Name: "v1.0.14"})
tags = append(tags, domain.Tag{Name: "v1.0.15"})
tags = append(tags, domain.Tag{Name: "v1.0.16"})
tags = append(tags, domain.Tag{Name: "v1.0.17"})
tags = append(tags, domain.Tag{Name: "v1.0.2"})
tags = append(tags, domain.Tag{Name: "v1.0.3"})
tags = append(tags, domain.Tag{Name: "v1.0.4"})
tags = append(tags, domain.Tag{Name: "v1.0.5"})
tags = append(tags, domain.Tag{Name: "v1.0.6"})
tags = append(tags, domain.Tag{Name: "v1.0.7"})
tags = append(tags, domain.Tag{Name: "v1.0.8"})
tags = append(tags, domain.Tag{Name: "v1.0.9"})
return tags
}