-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaccount_groups_test.go
127 lines (120 loc) · 2.94 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package cloudability
import (
"net/url"
"testing"
)
func TestNewAccountGroupsEndpoint(t *testing.T) {
testClient := NewClient("testapikey")
e := testClient.AccountGroups()
if e.BaseURL.String() != apiV1URL {
t.Errorf("AccountGroupsEndpoint BaseURL mismatch. Got %s. Expected %s", e.BaseURL.String(), apiV1URL)
}
if e.EndpointPath != accountGroupsEndpoint {
t.Errorf("AccountGroupsEndpoint EndpointPath mismatch. Got %s. Expected %s", e.EndpointPath, accountGroupsEndpoint)
}
}
func TestGetAccountGroups(t *testing.T) {
expectedAccountGroups := []AccountGroup{
{
ID: 1,
Name: "red",
Position: 1,
AccountGroupEntryValues: []string{
"red1",
"red2",
"red3",
},
},
{
ID: 2,
Name: "orange",
Position: 2,
AccountGroupEntryValues: []string{
"orange1",
"orange2",
},
},
{
ID: 3,
Name: "mauve",
Position: 3,
AccountGroupEntryValues: []string{},
},
}
testServer := testAPI(t, "GET", "/account_groups", expectedAccountGroups)
defer testServer.Close()
testClient := testClient(t, testServer)
e := testClient.AccountGroups()
accountGroups, err := e.GetAccountGroups()
if err != nil {
t.Fail()
}
if accountGroups == nil {
t.Fail()
}
// testCheckStructEqual(t, accountGroups, expectedAccountGroups)
}
func TestGetAccountGroup(t *testing.T) {
expectedAccountGroup := &AccountGroup{
ID: 2,
Name: "orange",
Position: 2,
AccountGroupEntryValues: []string{
"orange1",
"orange2",
},
}
testServer := testAPI(t, "GET", "/account_groups/2", &expectedAccountGroup)
defer testServer.Close()
testClient := testClient(t, testServer)
e := testClient.AccountGroups()
accountGroup, err := e.GetAccountGroup(2)
if err != nil {
t.Fail()
}
if accountGroup == nil {
t.Fail()
}
testCheckStructEqual(t, accountGroup, expectedAccountGroup)
}
func TestNewAccountGroup(t *testing.T) {
testServer := testAPI(t, "POST", "/account_groups", nil)
defer testServer.Close()
accountGroup := &AccountGroup{
Name: "purple",
Position: 5,
}
testClient := NewClient("testapikey")
e := testClient.AccountGroups()
e.BaseURL, _ = url.Parse(testServer.URL)
err := e.NewAccountGroup(accountGroup)
if err != nil {
t.Fail()
}
}
func TestUpdateAccountGroup(t *testing.T) {
testServer := testAPI(t, "PUT", "/account_groups/1", nil)
defer testServer.Close()
accountGroup := &AccountGroup{
ID: 1,
Name: "more purple",
}
testClient := NewClient("testapikey")
e := testClient.AccountGroups()
e.BaseURL, _ = url.Parse(testServer.URL)
err := e.UpdateAccountGroup(accountGroup)
if err != nil {
t.Fail()
}
}
func TestDeleteAccountGroup(t *testing.T) {
testServer := testAPI(t, "DELETE", "/account_groups/1", nil)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.AccountGroups()
e.BaseURL, _ = url.Parse(testServer.URL)
err := e.DeleteAccountGroup(1)
if err != nil {
t.Fail()
}
}