forked from digitalocean/godo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sizes_test.go
96 lines (80 loc) · 2.17 KB
/
sizes_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
package godo
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestSizes_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"sizes":[{"slug":"1"},{"slug":"2"}]}`)
})
sizes, _, err := client.Sizes.List(ctx, nil)
if err != nil {
t.Errorf("Sizes.List returned error: %v", err)
}
expected := []Size{{Slug: "1"}, {Slug: "2"}}
if !reflect.DeepEqual(sizes, expected) {
t.Errorf("Sizes.List returned %+v, expected %+v", sizes, expected)
}
}
func TestSizes_ListSizesMultiplePages(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"sizes": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/sizes/?page=2"}}}`)
})
_, resp, err := client.Sizes.List(ctx, nil)
if err != nil {
t.Fatal(err)
}
checkCurrentPage(t, resp, 1)
}
func TestSizes_RetrievePageByNumber(t *testing.T) {
setup()
defer teardown()
jBlob := `
{
"sizes": [{"id":1},{"id":2}],
"links":{
"pages":{
"next":"http://example.com/v2/sizes/?page=3",
"prev":"http://example.com/v2/sizes/?page=1",
"last":"http://example.com/v2/sizes/?page=3",
"first":"http://example.com/v2/sizes/?page=1"
}
}
}`
mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob)
})
opt := &ListOptions{Page: 2}
_, resp, err := client.Sizes.List(ctx, opt)
if err != nil {
t.Fatal(err)
}
checkCurrentPage(t, resp, 2)
}
func TestSize_String(t *testing.T) {
size := &Size{
Slug: "slize",
Memory: 123,
Vcpus: 456,
Disk: 789,
PriceMonthly: 123,
PriceHourly: 456,
Regions: []string{"1", "2"},
Available: true,
Transfer: 789,
}
stringified := size.String()
expected := `godo.Size{Slug:"slize", Memory:123, Vcpus:456, Disk:789, PriceMonthly:123, PriceHourly:456, Regions:["1" "2"], Available:true, Transfer:789}`
if expected != stringified {
t.Errorf("Size.String returned %+v, expected %+v", stringified, expected)
}
}