-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgocd_test.go
64 lines (48 loc) · 1.62 KB
/
gocd_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
package gocd_test
import (
"net/http"
"os"
"testing"
"github.com/nikhilsbhat/gocd-sdk-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetGoCDMethodNames(t *testing.T) {
t.Run("should list all method names", func(t *testing.T) {
response := gocd.GetGoCDMethodNames()
assert.Equal(t, 144, len(response))
assert.Equal(t, "AgentKillTask", response[0])
assert.Equal(t, "UpdatePipelineGroup", response[137])
})
}
func TestNewClient(t *testing.T) {
t.Run("should be able to use token based auth", func(t *testing.T) {
server := mockServer([]byte(mailServerJSON), http.StatusOK,
map[string]string{"Accept": gocd.HeaderVersionOne}, false, nil)
auth = gocd.Auth{
BearerToken: "dlskjmxelkjmxwlerkmwelkfmwek",
}
client := gocd.NewClient(server.URL, auth, "info", nil)
assert.NotNil(t, client)
})
t.Run("should be able to use token with CA based auth", func(t *testing.T) {
server := mockServer([]byte(mailServerJSON), http.StatusOK,
map[string]string{"Accept": gocd.HeaderVersionOne}, false, nil)
caContent, err := os.ReadFile("internal/fixtures/ca.sample.pem")
require.NoError(t, err)
auth = gocd.Auth{
BearerToken: "dlskjmxelkjmxwlerkmwelkfmwek",
}
client := gocd.NewClient(server.URL, auth, "info", caContent)
assert.NotNil(t, client)
})
t.Run("should be able no auth", func(t *testing.T) {
server := mockServer([]byte(mailServerJSON), http.StatusOK,
map[string]string{"Accept": gocd.HeaderVersionOne}, false, nil)
auth = gocd.Auth{
NoAuth: true,
}
client := gocd.NewClient(server.URL, auth, "info", nil)
assert.NotNil(t, client)
})
}