This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
forked from grezar/go-circleci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline_test.go
167 lines (139 loc) · 4.06 KB
/
pipeline_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
package circleci
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/google/go-cmp/cmp"
)
func Test_pipelines_List(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/pipeline/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", "application/json")
testHeader(t, r, "Circle-Token", client.token)
testQuery(t, r, "org-slug", "org1")
testQuery(t, r, "mine", "true")
fmt.Fprint(w, `{"items": [{"id": "1", "trigger": {"type": "explicit"}}], "next_page_token": "1"}`)
})
ctx := context.Background()
pl, err := client.Pipelines.List(ctx, PipelineListOptions{
OrgSlug: String("org1"),
Mine: Bool(true),
})
if err != nil {
t.Errorf("Pipelines.List got error: %v", err)
}
want := &PipelineList{
Items: []*Pipeline{
{
ID: "1",
Trigger: &Trigger{
Type: "explicit",
},
},
},
NextPageToken: "1",
}
if !cmp.Equal(pl, want) {
t.Errorf("Pipelines.List got %+v, want %+v", pl, want)
}
}
func Test_pipelines_Continue(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/pipeline/continue", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testHeader(t, r, "Accept", "application/json")
testHeader(t, r, "Circle-Token", client.token)
testBody(t, r, `{"continuation-key":"key1","configuration":"cfg1","parameters":{"deploy_prod":true}}`+"\n")
fmt.Fprint(w, `{"message": "string"}`)
})
ctx := context.Background()
err := client.Pipelines.Continue(ctx, PipelineContinueOptions{
ContinuationKey: String("key1"),
Configuration: String("cfg1"),
Parameters: map[string]interface{}{
"deploy_prod": true,
},
})
if err != nil {
t.Errorf("Pipelines.Continue got error: %v", err)
}
}
func Test_pipelines_Get(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
pipelineID := "pipeline1"
mux.HandleFunc(fmt.Sprintf("/pipeline/%s", pipelineID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", "application/json")
testHeader(t, r, "Circle-Token", client.token)
fmt.Fprint(w, `{"id": "1"}`)
})
ctx := context.Background()
p, err := client.Pipelines.Get(ctx, pipelineID)
if err != nil {
t.Errorf("Pipeline.Get got error: %v", err)
}
want := &Pipeline{
ID: "1",
}
if !cmp.Equal(p, want) {
t.Errorf("Pipeline.Get got %+v, want %+v", p, want)
}
}
func Test_pipelines_GetConfig(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
pipelineID := "pipeline1"
mux.HandleFunc(fmt.Sprintf("/pipeline/%s/config", pipelineID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", "application/json")
testHeader(t, r, "Circle-Token", client.token)
fmt.Fprint(w, `{"source": "a", "compiled": "b"}`)
})
ctx := context.Background()
p, err := client.Pipelines.GetConfig(ctx, pipelineID)
if err != nil {
t.Errorf("Pipeline.GetConfig got error: %v", err)
}
want := &PipelineConfig{
Source: "a",
Compiled: "b",
}
if !cmp.Equal(p, want) {
t.Errorf("Pipeline.GetConfig got %+v, want %+v", p, want)
}
}
func Test_pipelines_ListWorkflows(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
pipelineID := "pipeline1"
mux.HandleFunc(fmt.Sprintf("/pipeline/%s/workflow", pipelineID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", "application/json")
testHeader(t, r, "Circle-Token", client.token)
testQuery(t, r, "page-token", "1")
fmt.Fprint(w, `{"items": [{"pipeline_id": "pipeline1", "pipeline_number": 0}], "next_page_token": "2"}`)
})
ctx := context.Background()
p, err := client.Pipelines.ListWorkflows(ctx, pipelineID, PipelineListWorkflowsOptions{
PageToken: String("1"),
})
if err != nil {
t.Errorf("Pipeline.ListWorkflows got error: %v", err)
}
want := &WorkflowList{
Items: []*Workflow{
{
PipelineID: pipelineID,
},
},
NextPageToken: "2",
}
if !cmp.Equal(p, want) {
t.Errorf("Pipeline.ListWorkflows got %+v, want %+v", p, want)
}
}