forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipelines_test.go
247 lines (214 loc) · 7 KB
/
pipelines_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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestListProjectPipelines(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/pipelines", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectPipelinesOptions{Ref: String("master")}
piplines, _, err := client.Pipelines.ListProjectPipelines(1, opt)
if err != nil {
t.Errorf("Pipelines.ListProjectPipelines returned error: %v", err)
}
want := []*PipelineInfo{{ID: 1}, {ID: 2}}
if !reflect.DeepEqual(want, piplines) {
t.Errorf("Pipelines.ListProjectPipelines returned %+v, want %+v", piplines, want)
}
}
func TestGetPipeline(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/pipelines/5949167", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1,"status":"success"}`)
})
pipeline, _, err := client.Pipelines.GetPipeline(1, 5949167)
if err != nil {
t.Errorf("Pipelines.GetPipeline returned error: %v", err)
}
want := &Pipeline{ID: 1, Status: "success"}
if !reflect.DeepEqual(want, pipeline) {
t.Errorf("Pipelines.GetPipeline returned %+v, want %+v", pipeline, want)
}
}
func TestGetPipelineVariables(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/pipelines/5949167/variables", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"key":"RUN_NIGHTLY_BUILD","variable_type":"env_var","value":"true"},{"key":"foo","value":"bar"}]`)
})
variables, _, err := client.Pipelines.GetPipelineVariables(1, 5949167)
if err != nil {
t.Errorf("Pipelines.GetPipelineVariables returned error: %v", err)
}
want := []*PipelineVariable{{Key: "RUN_NIGHTLY_BUILD", Value: "true", VariableType: "env_var"}, {Key: "foo", Value: "bar"}}
if !reflect.DeepEqual(want, variables) {
t.Errorf("Pipelines.GetPipelineVariables returned %+v, want %+v", variables, want)
}
}
func TestGetPipelineTestReport(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/pipelines/123456/test_report", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
mustWriteHTTPResponse(t, w, "testdata/get_pipeline_testreport.json")
})
testreport, _, err := client.Pipelines.GetPipelineTestReport(1, 123456)
if err != nil {
t.Errorf("Pipelines.GetPipelineTestReport returned error: %v", err)
}
want := &PipelineTestReport{
TotalTime: 61.502,
TotalCount: 9,
SuccessCount: 5,
FailedCount: 0,
SkippedCount: 0,
ErrorCount: 4,
TestSuites: []PipelineTestSuites{
{
Name: "Failing",
TotalTime: 60.494,
TotalCount: 8,
SuccessCount: 4,
FailedCount: 0,
SkippedCount: 0,
ErrorCount: 4,
TestCases: []PipelineTestCases{
{
Status: "error",
Name: "Error testcase 1",
Classname: "MyClassOne",
File: "/path/file.ext",
ExecutionTime: 19.987,
SystemOutput: "output message\n\noutput message 2",
StackTrace: "java.lang.Exception: Stack trace\nat java.base/java.lang.Thread.dumpStack(Thread.java:1383)",
AttachmentURL: "http://foo.bar",
RecentFailures: RecentFailures{
Count: 10,
BaseBranch: "master",
},
},
{
Status: "error",
Name: "Error testcase 2",
Classname: "MyClass",
File: "",
ExecutionTime: 19.984,
SystemOutput: "",
StackTrace: "",
AttachmentURL: "",
RecentFailures: RecentFailures{},
},
{
Status: "error",
Name: "Error testcase 3",
Classname: "MyClass",
File: "",
ExecutionTime: 0.0,
SystemOutput: "Undefined message",
StackTrace: "",
AttachmentURL: "",
},
{
Status: "success",
Name: "Succes full testcase",
Classname: "MyClass",
File: "",
ExecutionTime: 19.7799999999999985,
SystemOutput: "",
StackTrace: "",
AttachmentURL: "",
}},
},
{
Name: "Succes suite",
TotalTime: 1.008,
TotalCount: 1,
SuccessCount: 1,
FailedCount: 0,
SkippedCount: 0,
ErrorCount: 0,
TestCases: []PipelineTestCases{{
Status: "success",
Name: "Succesfull testcase",
Classname: "MyClass",
File: "",
ExecutionTime: 1.008,
SystemOutput: "",
StackTrace: "",
AttachmentURL: "",
}},
},
}}
if !reflect.DeepEqual(want, testreport) {
t.Errorf("Pipelines.GetPipelineTestReport returned %+v, want %+v", testreport, want)
}
}
func TestCreatePipeline(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/pipeline", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprint(w, `{"id":1, "status":"pending"}`)
})
opt := &CreatePipelineOptions{Ref: String("master")}
pipeline, _, err := client.Pipelines.CreatePipeline(1, opt)
if err != nil {
t.Errorf("Pipelines.CreatePipeline returned error: %v", err)
}
want := &Pipeline{ID: 1, Status: "pending"}
if !reflect.DeepEqual(want, pipeline) {
t.Errorf("Pipelines.CreatePipeline returned %+v, want %+v", pipeline, want)
}
}
func TestRetryPipelineBuild(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/pipelines/5949167/retry", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprintln(w, `{"id":1, "status":"pending"}`)
})
pipeline, _, err := client.Pipelines.RetryPipelineBuild(1, 5949167)
if err != nil {
t.Errorf("Pipelines.RetryPipelineBuild returned error: %v", err)
}
want := &Pipeline{ID: 1, Status: "pending"}
if !reflect.DeepEqual(want, pipeline) {
t.Errorf("Pipelines.RetryPipelineBuild returned %+v, want %+v", pipeline, want)
}
}
func TestCancelPipelineBuild(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/pipelines/5949167/cancel", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprintln(w, `{"id":1, "status":"canceled"}`)
})
pipeline, _, err := client.Pipelines.CancelPipelineBuild(1, 5949167)
if err != nil {
t.Errorf("Pipelines.CancelPipelineBuild returned error: %v", err)
}
want := &Pipeline{ID: 1, Status: "canceled"}
if !reflect.DeepEqual(want, pipeline) {
t.Errorf("Pipelines.CancelPipelineBuild returned %+v, want %+v", pipeline, want)
}
}
func TestDeletePipeline(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/pipelines/5949167", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
_, err := client.Pipelines.DeletePipeline("1", 5949167)
if err != nil {
t.Errorf("Pipelines.DeletePipeline returned error: %v", err)
}
}