forked from vultr/govultr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubaccount_test.go
115 lines (100 loc) · 2.4 KB
/
subaccount_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
package govultr
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestSubAccountServiceHandler_Create(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/subaccounts", func(writer http.ResponseWriter, request *http.Request) {
response := `
{
"subaccount": {
"id": "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
"email": "subaccount@vultr.com",
"subaccount_name": "Acme Widgets LLC",
"subaccount_id": "472924",
"activated": false,
"balance": 0,
"pending_charges": 0
}
}`
fmt.Fprint(writer, response)
})
saReq := &SubAccountReq{
Email: "subaccount@vultr.com",
Name: "Acme Widgets LLC",
OtherID: "472924",
}
sa, _, err := client.SubAccount.Create(ctx, saReq)
if err != nil {
t.Errorf("SubAccount.Create returned error: %v", err)
}
expected := &SubAccount{
ID: "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
Email: "subaccount@vultr.com",
Name: "Acme Widgets LLC",
OtherID: "472924",
Activated: false,
Balance: 0,
PendingCharges: 0,
}
if !reflect.DeepEqual(sa, expected) {
t.Errorf("SubAccount.Create returned %+v, expected %+v", sa, expected)
}
}
func TestSubAccountServiceHandler_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/subaccounts", func(writer http.ResponseWriter, request *http.Request) {
response := `
{
"subaccounts": [
{
"id": "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
"email": "subaccount@vultr.com",
"subaccount_name": "Acme Widgets LLC",
"subaccount_id": "472924",
"activated": false,
"balance": 0,
"pending_charges": 0
}
],
"meta": {
"total": 1,
"links": {
"next": "",
"prev": ""
}
}
}`
fmt.Fprint(writer, response)
})
sas, meta, _, err := client.SubAccount.List(ctx, nil)
if err != nil {
t.Errorf("SubAccount.List returned error: %v", err)
}
expected := []SubAccount{
{
ID: "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
Email: "subaccount@vultr.com",
Name: "Acme Widgets LLC",
OtherID: "472924",
Activated: false,
Balance: 0,
PendingCharges: 0,
},
}
expectedMeta := &Meta{
Total: 1,
Links: &Links{},
}
if !reflect.DeepEqual(sas, expected) {
t.Errorf("SubAccount.List returned %+v, expected %+v", sas, expected)
}
if !reflect.DeepEqual(meta, expectedMeta) {
t.Errorf("SubAccount.List meta returned %+v, expected %+v", meta, expectedMeta)
}
}