-
Notifications
You must be signed in to change notification settings - Fork 24
/
charge_test.go
63 lines (51 loc) · 1.44 KB
/
charge_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
package civogo
import (
"testing"
"time"
)
func TestListCharges(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/charges": `[
{
"code": "instance-g1.small",
"label": "furry-apple.example.com",
"from": "2016-03-18T10:46:06Z",
"to": "2016-03-25T10:46:06Z",
"num_hours": 168,
"size_gb": 200
}
]
`,
})
defer server.Close()
from, _ := time.Parse(time.RFC3339, "2016-03-01T00:00:00Z")
to, _ := time.Parse(time.RFC3339, "2016-03-31T23:59:59Z")
got, err := client.ListCharges(from, to)
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got[0].Code != "instance-g1.small" {
t.Errorf("Expected %s, got %s", "instance-g1.small", got[0].Code)
}
if got[0].Label != "furry-apple.example.com" {
t.Errorf("Expected %s, got %s", "furry-apple.example.com", got[0].Label)
}
test, _ := time.Parse(time.RFC3339, "2016-03-18T10:46:06Z")
if got[0].From != test {
t.Errorf("Expected %v, got %v", test, got[0].From)
}
test, _ = time.Parse(time.RFC3339, "2016-03-25T10:46:06Z")
if got[0].To != test {
t.Errorf("Expected %v, got %v", test, got[0].To)
}
if got[0].Label != "furry-apple.example.com" {
t.Errorf("Expected %s, got %s", "furry-apple.example.com", got[0].Label)
}
if got[0].NumHours != 168 {
t.Errorf("Expected %d, got %d", 168, got[0].NumHours)
}
if got[0].SizeGigabytes != 200 {
t.Errorf("Expected %d, got %d", 200, got[0].SizeGigabytes)
}
}