-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathaccount_test.go
159 lines (146 loc) · 4.17 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
149
150
151
152
153
154
155
156
157
158
159
package govultr
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestAccountServiceHandler_Get(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/account", func(w http.ResponseWriter, r *http.Request) {
response := `
{
"account" : {
"balance": -5519.11,
"pending_charges": 57.03,
"last_payment_date": "2014-07-18 15:31:01",
"last_payment_amount": -1.00,
"name": "Test Tester",
"email" : "example@vultr.com",
"acls": [
"subscriptions",
"billing",
"support",
"provisioning"
]
}
}
`
fmt.Fprint(w, response)
})
account, _, err := client.Account.Get(ctx)
if err != nil {
t.Errorf("Account.Get returned error: %v", err)
}
expected := &Account{Balance: -5519.11, PendingCharges: 57.03, LastPaymentDate: "2014-07-18 15:31:01", LastPaymentAmount: -1.00, Name: "Test Tester", Email: "example@vultr.com", ACL: []string{"subscriptions", "billing", "support", "provisioning"}}
if !reflect.DeepEqual(account, expected) {
t.Errorf("Account.Get returned %+v, expected %+v", account, expected)
}
}
func TestAccountServiceHandler_GetBandwidth(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/account/bandwidth", func(w http.ResponseWriter, r *http.Request) {
response := `
{
"bandwidth": {
"previous_month": {
"timestamp_start": "1735689600",
"timestamp_end": "1738367999",
"gb_in": 0,
"gb_out": 0,
"total_instance_hours": 1,
"total_instance_count": 1,
"instance_bandwidth_credits": 1,
"free_bandwidth_credits": 2048,
"purchased_bandwidth_credits": 0,
"overage": 0,
"overage_unit_cost": 0.01,
"overage_cost": 0
},
"current_month_to_date": {
"timestamp_start": "1738368000",
"timestamp_end": "1739577600",
"gb_in": 0,
"gb_out": 0,
"total_instance_hours": 0,
"total_instance_count": 0,
"instance_bandwidth_credits": 0,
"free_bandwidth_credits": 2048,
"purchased_bandwidth_credits": 0,
"overage": 0,
"overage_unit_cost": 0.01,
"overage_cost": 0
},
"current_month_projected": {
"timestamp_start": "1738368000",
"timestamp_end": "1740787199",
"gb_in": 0,
"gb_out": 0,
"total_instance_hours": 0,
"total_instance_count": 0,
"instance_bandwidth_credits": 0,
"free_bandwidth_credits": 2048,
"purchased_bandwidth_credits": 0,
"overage": 0,
"overage_unit_cost": 0.01,
"overage_cost": 0
}
}
}
`
fmt.Fprint(w, response)
})
accountBandwidth, _, err := client.Account.GetBandwidth(ctx)
if err != nil {
t.Errorf("Account.GetBandwidth returned error: %v", err)
}
expected := &AccountBandwidth{
PreviousMonth: AccountBandwidthPeriod{
TimestampStart: "1735689600",
TimestampEnd: "1738367999",
GBIn: 0,
GBOut: 0,
TotalInstanceHours: 1,
TotalInstanceCount: 1,
InstanceBandwidthCredits: 1,
FreeBandwidthCredits: 2048,
PurchasedBandwidthCredits: 0,
Overage: 0,
OverageUnitCost: 0.01,
OverageCost: 0,
},
CurrentMonthToDate: AccountBandwidthPeriod{
TimestampStart: "1738368000",
TimestampEnd: "1739577600",
GBIn: 0,
GBOut: 0,
TotalInstanceHours: 0,
TotalInstanceCount: 0,
InstanceBandwidthCredits: 0,
FreeBandwidthCredits: 2048,
PurchasedBandwidthCredits: 0,
Overage: 0,
OverageUnitCost: 0.01,
OverageCost: 0,
},
CurrentMonthProjected: AccountBandwidthPeriod{
TimestampStart: "1738368000",
TimestampEnd: "1740787199",
GBIn: 0,
GBOut: 0,
TotalInstanceHours: 0,
TotalInstanceCount: 0,
InstanceBandwidthCredits: 0,
FreeBandwidthCredits: 2048,
PurchasedBandwidthCredits: 0,
Overage: 0,
OverageUnitCost: 0.01,
OverageCost: 0,
},
}
if !reflect.DeepEqual(accountBandwidth, expected) {
t.Errorf("Account.GetBandwidth returned %+v, expected %+v", accountBandwidth, expected)
}
}