forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipelines_test.go
145 lines (116 loc) · 4.27 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
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 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)
}
}