forked from thousandeyes/thousandeyes-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
73 lines (58 loc) · 2.25 KB
/
integration_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
package thousandeyes
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestClient_GetIntegrations(t *testing.T) {
out := `{"integrations":{"thirdParty":[{"authMethod":"Auth Token","integrationId":"pgd-9999","integrationName":"Test PD Integration","integrationType":"PAGER_DUTY"}],"webhook":[{"authMethod":"Basic","integrationId":"wb-999","integrationName":"Test Webhook Integration","integrationType":"WEBHOOK","target":"https://thousandeyes.com/"}]}}`
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/integrations.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
w.Write([]byte(out))
})
// Define expected values from the API (based on the JSON we print out above)
expected := []Integration{
{
AuthMethod: String("Auth Token"),
IntegrationID: String("pgd-9999"),
IntegrationName: String("Test PD Integration"),
IntegrationType: String("PAGER_DUTY"),
},
{
AuthMethod: String("Basic"),
IntegrationID: String("wb-999"),
IntegrationName: String("Test Webhook Integration"),
IntegrationType: String("WEBHOOK"),
Target: String("https://thousandeyes.com/"),
},
}
res, err := client.GetIntegrations()
teardown()
assert.Nil(t, err)
assert.Equal(t, &expected, res)
}
func TestClient_GetIntegrationsAlertError(t *testing.T) {
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/integrations.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
w.WriteHeader(http.StatusBadRequest)
})
_, err := client.GetIntegrations()
teardown()
assert.Error(t, err)
}
func TestClient_GetIntegrationsJsonError(t *testing.T) {
out := ` { "bgpMonitors": [ {aonitorId":1, "monitorType": "bgp","monitorName": "test", "ipAddress": "1.2.3.4"} ] }`
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/integrations.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
_, _ = w.Write([]byte(out))
})
_, err := client.GetIntegrations()
assert.Error(t, err)
assert.EqualError(t, err, "Could not decode JSON response: invalid character 'a' looking for beginning of object key string")
}