-
Notifications
You must be signed in to change notification settings - Fork 2
/
latest_backups_test.go
209 lines (194 loc) · 6.03 KB
/
latest_backups_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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package rediscloud_api
import (
"context"
"net/http/httptest"
"testing"
"github.com/RedisLabs/rediscloud-go-api/redis"
"github.com/RedisLabs/rediscloud-go-api/service/latest_backups"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetLatestBackup(t *testing.T) {
server := httptest.NewServer(
testServer(
"key",
"secret",
getRequest(
t,
"/subscriptions/12/databases/34/backup",
`{
"taskId": "50ec6172-8475-4ef6-8b3c-d61e688d8fe5",
"commandType": "databaseBackupStatusRequest",
"status": "received",
"description": "Task request received and is being queued for processing.",
"timestamp": "2024-04-15T09:08:04.222268Z",
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/50ec6172-8475-4ef6-8b3c-d61e688d8fe5",
"type": "GET",
"rel": "task"
}
]
}`,
),
getRequest(
t,
"/tasks/50ec6172-8475-4ef6-8b3c-d61e688d8fe5",
`{
"taskId": "50ec6172-8475-4ef6-8b3c-d61e688d8fe5",
"commandType": "databaseBackupStatusRequest",
"status": "processing-completed",
"description": "Request processing completed successfully and its resources are now being provisioned / de-provisioned.",
"timestamp": "2024-04-15T09:08:07.537915Z",
"response": {
"resourceId": 51051292,
"additionalResourceId": 12,
"resource": {}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/50ec6172-8475-4ef6-8b3c-d61e688d8fe5",
"type": "GET",
"rel": "self"
}
]
}`,
),
))
subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)
_, err = subject.LatestBackup.Get(context.TODO(), 12, 34)
require.NoError(t, err)
}
func TestGetFixedLatestBackup(t *testing.T) {
server := httptest.NewServer(
testServer(
"key",
"secret",
getRequest(
t,
"/fixed/subscriptions/12/databases/34/backup",
`{
"taskId": "ce2cbfea-9b15-4250-a516-f014161a8dd3",
"commandType": "databaseBackupStatusRequest",
"status": "received",
"description": "Task request received and is being queued for processing.",
"timestamp": "2024-04-15T09:52:23.963337Z",
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
"type": "GET",
"rel": "task"
}
]
}`,
),
getRequest(
t,
"/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
`{
"taskId": "ce2cbfea-9b15-4250-a516-f014161a8dd3",
"commandType": "databaseBackupStatusRequest",
"status": "processing-completed",
"description": "Request processing completed successfully and its resources are now being provisioned / de-provisioned.",
"timestamp": "2024-04-15T09:52:26.101936Z",
"response": {
"resource": {
"status": "success"
}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
"type": "GET",
"rel": "self"
}
]
}`,
),
))
subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)
actual, err := subject.LatestBackup.GetFixed(context.TODO(), 12, 34)
require.NoError(t, err)
assert.Equal(t, &latest_backups.LatestBackupStatus{
CommandType: redis.String("databaseBackupStatusRequest"),
Description: redis.String("Request processing completed successfully and its resources are now being provisioned / de-provisioned."),
Status: redis.String("processing-completed"),
ID: redis.String("ce2cbfea-9b15-4250-a516-f014161a8dd3"),
Response: &latest_backups.Response{
Resource: &latest_backups.Resource{
Status: redis.String("success"),
},
Error: nil,
},
}, actual)
}
func TestGetAALatestBackup(t *testing.T) {
server := httptest.NewServer(
testServer(
"key",
"secret",
getRequestWithQuery(
t,
"/subscriptions/12/databases/34/backup",
map[string][]string{"regionName": {"eu-west-2"}},
`{
"taskId": "ce2cbfea-9b15-4250-a516-f014161a8dd3",
"commandType": "databaseBackupStatusRequest",
"status": "received",
"description": "Task request received and is being queued for processing.",
"timestamp": "2024-04-15T09:52:23.963337Z",
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
"type": "GET",
"rel": "task"
}
]
}`,
),
getRequest(
t,
"/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
`{
"taskId": "ce2cbfea-9b15-4250-a516-f014161a8dd3",
"commandType": "databaseBackupStatusRequest",
"status": "processing-error",
"description": "Task request failed during processing. See error information for failure details.",
"timestamp": "2024-04-15T09:52:26.101936Z",
"response": {
"error": {
"type": "DATABASE_BACKUP_DISABLED",
"status": "400 BAD_REQUEST",
"description": "Database backup is disabled"
}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
"type": "GET",
"rel": "self"
}
]
}`,
),
))
subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)
actual, err := subject.LatestBackup.GetActiveActive(context.TODO(), 12, 34, "eu-west-2")
require.NoError(t, err)
assert.Equal(t, &latest_backups.LatestBackupStatus{
CommandType: redis.String("databaseBackupStatusRequest"),
Description: redis.String("Task request failed during processing. See error information for failure details."),
Status: redis.String("processing-error"),
ID: redis.String("ce2cbfea-9b15-4250-a516-f014161a8dd3"),
Response: &latest_backups.Response{
Error: &latest_backups.Error{
Type: redis.String("DATABASE_BACKUP_DISABLED"),
Description: redis.String("Database backup is disabled"),
Status: redis.String("400 BAD_REQUEST"),
},
},
}, actual)
}