-
Notifications
You must be signed in to change notification settings - Fork 24
/
region_test.go
131 lines (115 loc) · 3.6 KB
/
region_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
package civogo
import (
"testing"
)
func TestListRegions(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/regions": `[{"code":"NYC1","name":"New York 1","type":"civostack","out_of_capacity":false,"country":"us","country_name":"United States","features":{"iaas":false,"kubernetes":true}},{"code":"SVG1","name":"Stevenage 1","default":true,"type":"openstack","out_of_capacity":true,"country":"uk","country_name":"United Kingdom","features":{"iaas":true,"kubernetes":true}}]`,
})
defer server.Close()
got, err := client.ListRegions()
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got[0].Code != "NYC1" {
t.Errorf("Expected %s, got %s", "NYC1", got[0].Code)
}
if got[0].Name != "New York 1" {
t.Errorf("Expected %s, got %s", "New York 1", got[0].Name)
}
}
func TestFindRegions(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/regions": `[{"code":"NYC1","name":"New York 1","type":"civostack","out_of_capacity":false,"country":"us","country_name":"United States","features":{"iaas":false,"kubernetes":true}},{"code":"SVG1","name":"Stevenage 1","default":true,"type":"openstack","out_of_capacity":true,"country":"uk","country_name":"United Kingdom","features":{"iaas":true,"kubernetes":true}}]`,
})
defer server.Close()
got, err := client.FindRegion("nyc1")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got.Code != "NYC1" {
t.Errorf("Expected %s, got %s", "NYC1", got.Code)
}
if got.Name != "New York 1" {
t.Errorf("Expected %s, got %s", "New York 1", got.Name)
}
}
func TestCreateRegion(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/regions": `{
"code": "TEST1",
"country_iso_code": "US",
"private": false,
"account_ids": [],
"kubeconfig": "",
"compute_soft_deletion_hours": 24,
"features": {
"iaas": true,
"kubernetes": true,
"object_store": false,
"loadbalancer": false,
"dbaas": false,
"volume": true,
"paas": false,
"kfaas": false,
"public_ip_node_pools": false
}
}`,
})
defer server.Close()
createRegionRequest := &CreateRegionRequest{
Code: "TEST1",
CountryISOCode: "US",
Private: false,
AccountIDs: []string{},
Kubeconfig: "",
// ComputeSoftDeletionHours: utils.IntPtr(24),
Features: map[string]bool{
"iaas": true,
"kubernetes": true,
"object_store": false,
"loadbalancer": false,
"dbaas": false,
"volume": true,
"paas": false,
"kfaas": false,
"public_ip_node_pools": false,
},
}
got, err := client.CreateRegion(createRegionRequest)
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got.Code != "TEST1" {
t.Errorf("Expected %s, got %s", "TEST1", got.Code)
}
}
func TestConnectRegion(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/regions/connect": `{code: "TEST1"}`,
})
defer server.Close()
connectRegionRequest := &ConnectRegionRequest{
Code: "TEST1",
}
err := client.ConnectRegion(connectRegionRequest)
if err != nil {
t.Errorf("Request returned an error: %s", err)
}
}
func TestDisconnectRegion(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/regions/disconnect": `{code: "TEST1"}`,
})
defer server.Close()
disconnectRegionRequest := &DisconnectRegionRequest{
Code: "TEST1",
}
err := client.DisconnectRegion(disconnectRegionRequest)
if err != nil {
t.Errorf("Request returned an error: %s", err)
}
}