-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_test.go
178 lines (151 loc) · 4.19 KB
/
job_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
package jenkins
import (
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestName(t *testing.T) {
assert.Equal(t, "folder", folder.Name)
assert.Equal(t, "folder", folder.FullName)
assert.Equal(t, "folder", folder.FullDisplayName)
assert.Equal(t, "pipeline", pipeline.Name)
assert.Equal(t, "folder/pipeline", pipeline.FullName)
assert.Equal(t, "folder » pipeline", pipeline.FullDisplayName)
}
func TestRename(t *testing.T) {
_, err := pipeline.Rename("pipeline1")
assert.Nil(t, err)
newPipeline, err := folder.Get("pipeline1")
assert.Nil(t, err)
assert.Equal(t, pipeline.URL, newPipeline.URL)
assert.Equal(t, pipeline.Name, newPipeline.Name)
// old job 'pipeline' should not exist
old, err := folder.Get("pipeline")
assert.NotNil(t, err)
assert.Nil(t, old)
// revert
_, err = pipeline.Rename("pipeline")
assert.Nil(t, err)
}
func TestIsBuildable(t *testing.T) {
buildable, err := pipeline.IsBuildable()
assert.Nil(t, err)
assert.True(t, buildable)
// disable and check
_, err = pipeline.Disable()
assert.Nil(t, err)
buildable, err = pipeline.IsBuildable()
assert.Nil(t, err)
assert.False(t, buildable)
// enable and check
_, err = pipeline.Enable()
assert.Nil(t, err)
buildable, err = pipeline.IsBuildable()
assert.Nil(t, err)
assert.True(t, buildable)
// test foler
buildable, err = folder.IsBuildable()
assert.Nil(t, err)
assert.False(t, buildable)
}
func TestList(t *testing.T) {
// test job.List for folder
jobs, err := folder.List(0)
assert.Nil(t, err)
assert.Len(t, jobs, 3)
// test job.List for job
jobs, err = pipeline.List(0)
assert.NotNil(t, err)
assert.Nil(t, jobs)
}
func TestGetParent(t *testing.T) {
fParent, err := folder.GetParent()
assert.NotNil(t, err)
assert.Nil(t, fParent)
pParent, err := pipeline.GetParent()
assert.Nil(t, err)
assert.Equal(t, folder.URL, pParent.URL)
}
func TestGetConfig(t *testing.T) {
conf, err := pipeline.GetConfigure()
assert.Nil(t, err)
assert.Contains(t, conf, os.Getenv("JENKINS_VERSION"))
}
func TestListBuilds(t *testing.T) {
builds, err := pipeline.ListBuilds()
assert.Nil(t, err)
assert.Len(t, builds, 1)
builds, err = folder.ListBuilds()
assert.NotNil(t, err)
assert.Nil(t, builds)
}
func TestFolderCredentials(t *testing.T) {
cm := folder.Credentials()
creds, err := cm.List()
assert.Nil(t, err)
assert.Len(t, creds, 0)
_, err = cm.Create(strings.NewReader(credConf))
assert.Nil(t, err)
creds, err = cm.List()
assert.Nil(t, err)
assert.Len(t, creds, 1)
_, err = cm.Delete("user-id")
assert.Nil(t, err)
creds, err = cm.List()
assert.Nil(t, err)
assert.Len(t, creds, 0)
}
func TestSetDescription(t *testing.T) {
description, err := pipeline.GetDescription()
assert.Nil(t, err)
assert.Empty(t, description)
msg := "testing job for go jenkins"
_, err = pipeline.SetDescription(msg)
assert.Nil(t, err)
description, err = pipeline.GetDescription()
assert.Nil(t, err)
assert.Equal(t, msg, description)
}
func TestGetBuildFunctions(t *testing.T) {
expect_build := setupBuild(t)
// test job.GetBuild
build, err := pipeline.GetBuild(expect_build.Number)
assert.Nil(t, err)
assert.Equal(t, expect_build.Number, build.Number)
// test job.GetLastBuild
build, err = pipeline.GetLastBuild()
assert.Nil(t, err)
assert.Equal(t, expect_build.Number, build.Number)
// test job.GetLastBuild
build, err = pipeline.GetFirstBuild()
assert.Nil(t, err)
assert.Equal(t, expect_build.Number, build.Number)
// test for folder
build, err = folder.GetFirstBuild()
assert.NotNil(t, err)
assert.Nil(t, build)
}
func TestMove(t *testing.T) {
_, err := pipeline.Move("/folder/folder1")
assert.Nil(t, err)
job, err := jenkins.GetJob("folder/pipeline")
assert.NotNil(t, err)
assert.Nil(t, job)
job, err = jenkins.GetJob("folder/folder1/pipeline")
assert.Nil(t, err)
assert.Contains(t, job.URL, "folder1/job/pipeline")
//revert change
_, err = pipeline.Move("folder")
assert.Nil(t, err)
}
func TestCopy(t *testing.T) {
_, err := folder.Copy("pipeline", "new_pipeline")
assert.Nil(t, err)
job, err := jenkins.GetJob("folder/new_pipeline")
assert.Nil(t, err)
assert.Equal(t, job.Class, pipeline.Class)
assert.Contains(t, job.URL, "new_pipeline")
// clean
jenkins.DeleteJob("folder/new_pipeline")
}