forked from thousandeyes/thousandeyes-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgp_monitor_test.go
61 lines (46 loc) · 1.74 KB
/
bgp_monitor_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
package thousandeyes
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestClient_GetBGPMonitors(t *testing.T) {
out := ` { "bgpMonitors": [ {"monitorId":1, "monitorType": "bgp","monitorName": "test", "ipAddress": "1.2.3.4"} ] }`
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/bgp-monitors.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 := BGPMonitors{
BGPMonitor{MonitorID: Int(1), MonitorName: String("test"), MonitorType: String("bgp"), IPAddress: String("1.2.3.4")},
}
res, err := client.GetBPGMonitors()
teardown()
assert.Nil(t, err)
assert.Equal(t, &expected, res)
}
func TestClient_GetBGPMonitorsAlertError(t *testing.T) {
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/bgp-monitors.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
w.WriteHeader(http.StatusBadRequest)
})
_, err := client.GetBPGMonitors()
teardown()
assert.Error(t, err)
}
func TestClient_GetBPGMonitorsJsonError(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("/bgp-monitors.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
_, _ = w.Write([]byte(out))
})
_, err := client.GetBPGMonitors()
assert.Error(t, err)
assert.EqualError(t, err, "Could not decode JSON response: invalid character 'a' looking for beginning of object key string")
}