-
Notifications
You must be signed in to change notification settings - Fork 23
/
account_groups_test.go
64 lines (49 loc) · 1.64 KB
/
account_groups_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 thousandeyes
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestClient_GetAccountGroups(t *testing.T) {
out := `{"accountGroups":[{"accountGroupName":"Test Account", "aid":1}]}`
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/account-groups.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 := []SharedWithAccount{
{
AccountGroupName: String("Test Account"),
AID: Int64(1),
},
}
res, err := client.GetAccountGroups()
teardown()
assert.Nil(t, err)
assert.Equal(t, &expected, res)
}
func TestClient_GetAccountGroupsAlertError(t *testing.T) {
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/account-groups.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
w.WriteHeader(http.StatusBadRequest)
})
_, err := client.GetAccountGroups()
teardown()
assert.Error(t, err)
}
func TestClient_GetAccountGroupsJsonError(t *testing.T) {
out := `{"accountGroups":[{accountGroupName":"Test Account", "aid":1}]}`
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/account-groups.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
_, _ = w.Write([]byte(out))
})
_, err := client.GetAccountGroups()
assert.Error(t, err)
assert.EqualError(t, err, "Could not decode JSON response: invalid character 'a' looking for beginning of object key string")
}