-
Notifications
You must be signed in to change notification settings - Fork 24
/
database_test.go
110 lines (97 loc) · 2.18 KB
/
database_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
package civogo
import (
"reflect"
"testing"
)
func TestListDatabases(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/databases": `{"page": 1, "per_page": 20, "pages": 2, "items":[{"id": "12345", "name": "test-db"}]}`,
})
defer server.Close()
got, err := client.ListDatabases()
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := &PaginatedDatabases{
Page: 1,
PerPage: 20,
Pages: 2,
Items: []Database{
{
ID: "12345",
Name: "test-db",
},
},
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}
func TestFindDatabase(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/databases": `{
"page": 1,
"per_page": 20,
"pages": 1,
"items": [
{
"id": "12345",
"name": "test-db"
}
]
}`,
})
defer server.Close()
got, _ := client.FindDatabase("test-db")
if got.ID != "12345" {
t.Errorf("Expected %s, got %s", "12345", got.ID)
}
}
func TestNewDatabase(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/databases": `{
"id": "12345",
"name": "test-db",
"size": "g3.db.xsmall",
"software": "MySQL",
"status" : "Ready"
}`,
})
defer server.Close()
cfg := &CreateDatabaseRequest{
Name: "test-db",
Size: "g3.db.xsmall",
Software: "MySQL",
}
got, err := client.NewDatabase(cfg)
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := &Database{
ID: "12345",
Name: "test-db",
Size: "g3.db.xsmall",
Software: "MySQL",
Status: "Ready",
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}
func TestDeleteDatabase(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/databases/12345": `{"result": "success"}`,
})
defer server.Close()
got, err := client.DeleteDatabase("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)
}
}