-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcctray_test.go
88 lines (73 loc) · 2.76 KB
/
cctray_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
package gocd_test
import (
_ "embed"
"net/http"
"testing"
"github.com/nikhilsbhat/gocd-sdk-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
//go:embed internal/fixtures/cctray.xml
var ccTrayJSON string
func Test_client_GetCCTray(t *testing.T) {
t.Run("should be able to fetch the cctray successfully", func(t *testing.T) {
server := mockServer([]byte(ccTrayJSON), http.StatusOK,
nil, true, nil)
client := gocd.NewClient(server.URL, auth, "info", nil)
expected := []gocd.Project{
{
Activity: "Sleeping",
LastBuildLabel: "1",
LastBuildStatus: "Failure",
LastBuildTime: "2023-09-11T03:09:59Z",
Name: "action-movies :: build",
WebURL: "http://localhost:8153/go/pipelines/action-movies/1/build/1",
},
{
Activity: "Sleeping",
LastBuildLabel: "1",
LastBuildStatus: "Failure",
LastBuildTime: "2023-09-11T03:09:59Z",
Name: "action-movies :: build :: build",
WebURL: "http://localhost:8153/go/tab/build/detail/action-movies/1/build/1/build",
},
{
Activity: "Sleeping",
LastBuildLabel: "1",
LastBuildStatus: "Failure",
LastBuildTime: "2023-09-11T03:09:59Z",
Name: "animation-movies :: build",
WebURL: "http://localhost:8153/go/pipelines/animation-movies/1/build/1",
},
}
actual, err := client.GetCCTray()
require.NoError(t, err)
assert.Equal(t, expected, actual)
})
t.Run("should error out while fetching all cctray present in GoCD as GoCD returned non ok status code", func(t *testing.T) {
server := mockServer([]byte(""), http.StatusBadGateway,
nil, true, nil)
client := gocd.NewClient(server.URL, auth, "info", nil)
actual, err := client.GetCCTray()
require.EqualError(t, err, "got 502 from GoCD while making GET call for "+server.URL+
"/cctray.xml\nwith BODY:")
assert.Nil(t, actual)
})
t.Run("should error out while fetching all cctray from GoCD as server returned malformed response", func(t *testing.T) {
server := mockServer([]byte("ccTrayJSON"), http.StatusOK, nil,
true, nil)
client := gocd.NewClient(server.URL, auth, "info", nil)
actual, err := client.GetCCTray()
require.EqualError(t, err, "reading response body errored with: EOF")
assert.Nil(t, actual)
})
t.Run("should error out while fetching all cctray present in GoCD as server is not reachable", func(t *testing.T) {
client := gocd.NewClient("http://localhost:8156/go", auth, "info", nil)
client.SetRetryCount(1)
client.SetRetryWaitTime(1)
actual, err := client.GetCCTray()
require.EqualError(t, err, "call made to get cctray errored with: "+
"Get \"http://localhost:8156/go/cctray.xml\": dial tcp [::1]:8156: connect: connection refused")
assert.Nil(t, actual)
})
}