forked from vultr/govultr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regions_test.go
68 lines (54 loc) · 1.7 KB
/
regions_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
package govultr
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRegionServiceHandler_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/regions", func(writer http.ResponseWriter, request *http.Request) {
response := `{"regions":[{"id":"ams","city": "test", "country":"NL","continent":"Europe","options":["ddos_protection"]}],"meta":{"total":1,"links":{"next":"","prev":""}}}`
fmt.Fprint(writer, response)
})
region, meta, _, err := client.Region.List(ctx, nil)
if err != nil {
t.Errorf("Region.List returned error: %v", err)
}
expectedRegion := []Region{
{
ID: "ams",
City: "test",
Country: "NL",
Continent: "Europe",
Options: []string{"ddos_protection"},
},
}
expectedMeta := &Meta{
Total: 1,
Links: &Links{},
}
if !reflect.DeepEqual(region, expectedRegion) {
t.Errorf("Region.List region returned %+v, expected %+v", region, expectedRegion)
}
if !reflect.DeepEqual(meta, expectedMeta) {
t.Errorf("Region.List meta returned %+v, expected %+v", meta, expectedMeta)
}
}
func TestRegionServiceHandler_Availability(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/regions/ewr/availability", func(writer http.ResponseWriter, request *http.Request) {
response := `{"available_plans":["vc2-1c-1gb","vc2-1c-2gb","vc2-2c-4gb"]}`
fmt.Fprint(writer, response)
})
region, _, err := client.Region.Availability(ctx, "ewr", "")
if err != nil {
t.Errorf("Region.Availability returned error: %v", err)
}
expected := &PlanAvailability{AvailablePlans: []string{"vc2-1c-1gb", "vc2-1c-2gb", "vc2-2c-4gb"}}
if !reflect.DeepEqual(region, expected) {
t.Errorf("Region.Availability returned %+v, expected %+v", region, expected)
}
}