forked from civo/civogo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kfcluster_test.go
108 lines (95 loc) · 2.2 KB
/
kfcluster_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
package civogo
import (
"reflect"
"testing"
)
func TestListKfClusters(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/kfclusters": `{"page": 1, "per_page": 20, "pages": 2, "items":[{"id": "12345", "name": "test-kfcluster"}]}`,
})
defer server.Close()
got, err := client.ListKfClusters()
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := &PaginatedKfClusters{
Page: 1,
PerPage: 20,
Pages: 2,
Items: []KfCluster{
{
ID: "12345",
Name: "test-kfcluster",
},
},
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}
func TestFindKfCluster(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/kfclusters": `{
"page": 1,
"per_page": 20,
"pages": 1,
"items": [
{
"id": "12345",
"name": "test-kfcluster"
}
]
}`,
})
defer server.Close()
got, _ := client.FindKfCluster("test-kfcluster")
if got.ID != "12345" {
t.Errorf("Expected %s, got %s", "12345", got.ID)
}
}
func TestCreateKfCluster(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/kfclusters": `{
"id": "12345",
"name": "test-kfcluster",
"size": "g3.kf.small",
"network_id": "09090"
}`,
})
defer server.Close()
cfg := CreateKfClusterReq{
Name: "test-kfcluster",
Size: "g3.kf.small",
NetworkID: "09090",
}
got, err := client.CreateKfCluster(cfg)
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := &KfCluster{
ID: "12345",
Name: "test-kfcluster",
Size: "g3.kf.small",
NetworkID: "09090",
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}
func TestDeleteKfCluster(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/kfclusters/12345": `{"result": "success"}`,
})
defer server.Close()
got, err := client.DeleteKfCluster("12345")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := &SimpleResponse{Result: "success"}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}