-
Notifications
You must be signed in to change notification settings - Fork 11
/
account_test.go
137 lines (115 loc) · 2.77 KB
/
account_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
128
129
130
131
132
133
134
135
136
137
package udnssdk
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func Test_Accounts_Select_Live(t *testing.T) {
if !enableIntegrationTests {
t.SkipNow()
}
if !enableAccountTests {
t.SkipNow()
}
testClient, err := NewClient(testUsername, testPassword, testBaseURL)
if err != nil {
t.Fatal(err)
}
accounts, resp, err := testClient.Accounts.Select()
if err != nil {
if resp != nil && resp.StatusCode == 404 {
t.SkipNow()
}
t.Fatal(err)
}
t.Logf("Accounts: %+v \n", accounts)
t.Logf("Response: %+v\n", resp)
}
func Test_Accounts_Select(t *testing.T) {
want := []Account{
Account{
AccountName: "terraform",
AccountHolderUserName: "terraform",
OwnerUserName: "terraform",
NumberOfUsers: 1,
NumberOfGroups: 1,
AccountType: "ORGANIZATION",
},
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
resp := AccountListDTO{
Accounts: want,
Resultinfo: ResultInfo{
TotalCount: len(want),
Offset: 0,
ReturnedCount: len(want),
},
}
mess, _ := json.Marshal(resp)
fmt.Fprintln(w, string(mess))
}))
defer ts.Close()
testClient, _ := newStubClient(testUsername, testPassword, ts.URL, "", "")
accounts, _, err := testClient.Accounts.Select()
if err != nil {
t.Fatal(err)
}
if len(accounts) != len(want) {
t.Errorf("len(accounts): %+v, want: %+v", len(accounts), len(want))
}
for i, a := range accounts {
w := want[i]
if a != w {
t.Errorf("accounts[%d]: %+v, want: %+v", i, a, w)
}
}
}
func Test_Accounts_Find(t *testing.T) {
want := Account{
AccountName: "terraform",
AccountHolderUserName: "terraform",
OwnerUserName: "terraform",
NumberOfUsers: 1,
NumberOfGroups: 1,
AccountType: "ORGANIZATION",
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
resp := want
mess, _ := json.Marshal(resp)
fmt.Fprintln(w, string(mess))
}))
defer ts.Close()
testClient, _ := newStubClient(testUsername, testPassword, ts.URL, "", "")
a, _, err := testClient.Accounts.Find("terraform")
if err != nil {
t.Fatal(err)
}
if a != want {
t.Errorf("account: %+v, want: %+v", a, want)
}
}
func Test_AccountsURI(t *testing.T) {
uri := AccountsURI()
want := "accounts"
if uri != want {
t.Errorf("AccountsURI: %+v, want: %+v", uri, want)
}
}
func Test_Accounts_URI_empty(t *testing.T) {
a := AccountKey("")
want := "accounts"
uri := a.URI()
if uri != want {
t.Errorf("AccountKey.URI: %+v, want: %+v", uri, want)
}
}
func Test_Accounts_URI_nonempty(t *testing.T) {
a := AccountKey("foo")
want := "accounts/foo"
uri := a.URI()
if uri != want {
t.Errorf("AccountKey.URI: %+v, want: %+v", uri, want)
}
}