-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgocd_pipeline_client_test.go
49 lines (42 loc) · 1.57 KB
/
gocd_pipeline_client_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
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func Test_shouldReturnTrueWhenPipelineIsAvailable(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
js, _ := json.Marshal(GoCDPipelineResponse{Schedulable: true})
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(js)
}))
defer ts.Close()
if result, err := isPipelineAvailable("pipeName", ts.URL, "blah"); result != true && err != nil {
t.Error("Decode didn't happen correctly, action could not be retrieved")
}
}
func Test_shouldReturnFalseWhenPipelineIsUnavailable(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
js, _ := json.Marshal(GoCDPipelineResponse{Schedulable: false})
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(js)
}))
defer ts.Close()
if result, err := isPipelineAvailable("pipeName", ts.URL, "blah"); result != false && err != nil {
t.Error("Decode didn't happen correctly, action could not be retrieved")
}
}
func Test_shouldReturnFalseWithErrorWhenPipelineCheckGoesWrong(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
return
}))
defer ts.Close()
if result, err := isPipelineAvailable("pipeName", ts.URL, "blah"); result != false && err == nil {
t.Error("Decode didn't happen correctly, action could not be retrieved")
}
}