-
Notifications
You must be signed in to change notification settings - Fork 301
/
account_test.go
148 lines (129 loc) · 3.93 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
138
139
140
141
142
143
144
145
146
147
148
package godo
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestAccountGet(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/account", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
response := `
{ "account": {
"droplet_limit": 25,
"floating_ip_limit": 25,
"reserved_ip_limit": 25,
"volume_limit": 22,
"email": "sammy@digitalocean.com",
"name": "Sammy the Shark",
"uuid": "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
"email_verified": true
}
}`
fmt.Fprint(w, response)
})
acct, _, err := client.Account.Get(ctx)
if err != nil {
t.Errorf("Account.Get returned error: %v", err)
}
expected := &Account{
DropletLimit: 25,
FloatingIPLimit: 25,
ReservedIPLimit: 25,
Email: "sammy@digitalocean.com",
Name: "Sammy the Shark",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
EmailVerified: true,
VolumeLimit: 22,
}
if !reflect.DeepEqual(acct, expected) {
t.Errorf("Account.Get returned %+v, expected %+v", acct, expected)
}
}
func TestAccountString(t *testing.T) {
acct := &Account{
DropletLimit: 25,
FloatingIPLimit: 25,
ReservedIPLimit: 25,
VolumeLimit: 22,
Email: "sammy@digitalocean.com",
Name: "Sammy the Shark",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
EmailVerified: true,
Status: "active",
StatusMessage: "message",
}
stringified := acct.String()
expected := `godo.Account{DropletLimit:25, FloatingIPLimit:25, ReservedIPLimit:25, VolumeLimit:22, Email:"sammy@digitalocean.com", Name:"Sammy the Shark", UUID:"b6fr89dbf6d9156cace5f3c78dc9851d957381ef", EmailVerified:true, Status:"active", StatusMessage:"message"}`
if expected != stringified {
t.Errorf("\n got %+v\nexpected %+v", stringified, expected)
}
}
func TestAccountGetWithTeam(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/account", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
response := `
{ "account": {
"droplet_limit": 25,
"floating_ip_limit": 25,
"volume_limit": 22,
"email": "sammy@digitalocean.com",
"name": "Sammy the Shark",
"uuid": "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
"email_verified": true,
"team": {
"name": "My Team",
"uuid": "b6fr89dbf6d9156cace5f3c78dc9851d957381ef"
}
}
}`
fmt.Fprint(w, response)
})
acct, _, err := client.Account.Get(ctx)
if err != nil {
t.Errorf("Account.Get returned error: %v", err)
}
expected := &Account{
DropletLimit: 25,
FloatingIPLimit: 25,
Email: "sammy@digitalocean.com",
Name: "Sammy the Shark",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
EmailVerified: true,
VolumeLimit: 22,
Team: &TeamInfo{
Name: "My Team",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
},
}
if !reflect.DeepEqual(acct, expected) {
t.Errorf("Account.Get returned %+v, expected %+v", acct, expected)
}
}
func TestAccountStringWithTeam(t *testing.T) {
acct := &Account{
DropletLimit: 25,
FloatingIPLimit: 25,
ReservedIPLimit: 25,
VolumeLimit: 22,
Email: "sammy@digitalocean.com",
Name: "Sammy the Shark",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
EmailVerified: true,
Status: "active",
StatusMessage: "message",
Team: &TeamInfo{
Name: "My Team",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
},
}
stringified := acct.String()
expected := `godo.Account{DropletLimit:25, FloatingIPLimit:25, ReservedIPLimit:25, VolumeLimit:22, Email:"sammy@digitalocean.com", Name:"Sammy the Shark", UUID:"b6fr89dbf6d9156cace5f3c78dc9851d957381ef", EmailVerified:true, Status:"active", StatusMessage:"message", Team:godo.TeamInfo{Name:"My Team", UUID:"b6fr89dbf6d9156cace5f3c78dc9851d957381ef"}}`
if expected != stringified {
t.Errorf("\n got %+v\nexpected %+v", stringified, expected)
}
}