forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipelines_test.go
111 lines (89 loc) · 3.13 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
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestListProjectPipelines(t *testing.T) {
mux, server, client := setup()
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 := PipelineList{{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()
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 TestCreatePipeline(t *testing.T) {
mux, server, client := setup()
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()
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()
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)
}
}