forked from vultr/govultr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_test.go
175 lines (146 loc) · 3.32 KB
/
backup_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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package govultr
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestBackupServiceHandler_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/backups", func(w http.ResponseWriter, r *http.Request) {
response := `
{
"backups": [
{
"id": "543d34149403a",
"date_created": "2014-10-14 12:40:40",
"description": "Automatic server backup",
"size": 42949672960,
"status": "complete"
}
],
"meta": {
"total":8,
"links": {
"next":"",
"prev":""
}
}
}
`
fmt.Fprint(w, response)
})
backups, meta, _, err := client.Backup.List(ctx, nil)
if err != nil {
t.Errorf("Backup.List returned error: %v", err)
}
expected := []Backup{
{
ID: "543d34149403a",
DateCreated: "2014-10-14 12:40:40",
Description: "Automatic server backup",
Size: 42949672960,
Status: "complete",
},
}
expectedMeta := &Meta{
Total: 8,
Links: &Links{},
}
if !reflect.DeepEqual(backups, expected) {
t.Errorf("Backup.List returned %+v, expected %+v", backups, expected)
}
if !reflect.DeepEqual(meta, expectedMeta) {
t.Errorf("Backup.List returned %+v, expected %+v", meta, expectedMeta)
}
}
func TestBackupServiceHandler_ListEmpty(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/backups", func(w http.ResponseWriter, r *http.Request) {
response := `
{
"backups": [],
"meta": {
"total":0,
"links": {
"next":"",
"prev":""
}
}
}
`
fmt.Fprint(w, response)
})
backups, meta, _, err := client.Backup.List(ctx, nil)
if err != nil {
t.Errorf("Backup.List returned error: %v", err)
}
expected := []Backup{}
if !reflect.DeepEqual(backups, expected) {
t.Errorf("Backup.List returned %+v, expected %+v", backups, expected)
}
expectedMeta := &Meta{
Total: 0,
Links: &Links{
Next: "",
Prev: "",
},
}
if !reflect.DeepEqual(meta, expectedMeta) {
t.Errorf("Backup.List meta returned %+v, expected %+v", meta, expectedMeta)
}
}
func TestBackupServiceHandler_Get(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/backups/543d34149403a", func(w http.ResponseWriter, r *http.Request) {
response := `
{
"backup": {
"id": "543d34149403a",
"date_created": "2014-10-14 12:40:40",
"description": "Automatic server backup",
"size": 42949672960,
"status": "complete"
}
}
`
fmt.Fprint(w, response)
})
backup, _, err := client.Backup.Get(ctx, "543d34149403a")
if err != nil {
t.Errorf("Backup.Get returned error: %v", err)
}
expected := &Backup{
ID: "543d34149403a",
DateCreated: "2014-10-14 12:40:40",
Description: "Automatic server backup",
Size: 42949672960,
Status: "complete",
}
if !reflect.DeepEqual(backup, expected) {
t.Errorf("Backup.Get returned %+v, expected %+v", backup, expected)
}
}
func TestBackupServiceHandler_GetEmpty(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/backups/543d34149403a", func(w http.ResponseWriter, r *http.Request) {
response := `
{
"backup": {}
}
`
fmt.Fprint(w, response)
})
backup, _, err := client.Backup.Get(ctx, "543d34149403a")
if err != nil {
t.Errorf("Backup.Get returned error: %v", err)
}
expected := &Backup{}
if !reflect.DeepEqual(backup, expected) {
t.Errorf("Backup.Get returned %+v, expected %+v", backup, expected)
}
}