-
Notifications
You must be signed in to change notification settings - Fork 2
/
task_test.go
105 lines (96 loc) · 3.18 KB
/
task_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
package rediscloud_api
import (
"context"
"errors"
"net/http/httptest"
"testing"
"github.com/RedisLabs/rediscloud-go-api/internal"
"github.com/RedisLabs/rediscloud-go-api/redis"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTaskErrorsGetUnwrapped(t *testing.T) {
s := httptest.NewServer(testServer("key", "secret", deleteRequest(t, "/cloud-accounts/1", `{
"taskId": "task",
"commandType": "cloudAccountDeleteRequest",
"status": "received",
"description": "Task request received and is being queued for processing.",
"timestamp": "2020-11-02T09:05:34.3Z",
"_links": {
"task": {
"href": "https://example.org",
"title": "getTaskStatusUpdates",
"type": "GET"
}
}
}`), getRequest(t, "/tasks/task", `{
"taskId": "e02b40d6-1395-4861-a3b9-ecf829d835fd",
"commandType": "cloudAccountDeleteRequest",
"status": "processing-error",
"timestamp": "2020-10-28T09:58:16.798Z",
"response": {
"error": {
"type": "SUBSCRIPTION_PI_NOT_FOUND",
"status": "400 BAD_REQUEST",
"description": "Payment info was not found for subscription. Use 'GET /payment-methods' to lookup valid payment methods for current Account"
}
},
"_links": {
"self": {
"href": "https://example.com",
"type": "GET"
}
}
}`)))
subject, err := clientFromTestServer(s, "key", "secret")
require.NoError(t, err)
err = subject.CloudAccount.Delete(context.TODO(), 1)
assert.Equal(t, &internal.Error{
Type: redis.String("SUBSCRIPTION_PI_NOT_FOUND"),
Description: redis.String("Payment info was not found for subscription. Use 'GET /payment-methods' to lookup valid payment methods for current Account"),
Status: redis.String("400 BAD_REQUEST"),
}, errors.Unwrap(err))
}
func TestTask_Handles404Eventually(t *testing.T) {
s := httptest.NewServer(testServer("key", "secret", deleteRequest(t, "/cloud-accounts/1", `{
"taskId": "task",
"commandType": "cloudAccountDeleteRequest",
"status": "received",
"description": "Task request received and is being queued for processing.",
"timestamp": "2020-11-02T09:05:34.3Z",
"_links": {
"task": {
"href": "https://example.org",
"title": "getTaskStatusUpdates",
"type": "GET"
}
}
}`), getRequest(t, "/tasks/task", `{
"taskId": "e02b40d6-1395-4861-a3b9-ecf829d835fd",
"commandType": "cloudAccountDeleteRequest",
"status": "initialized",
"timestamp": "2020-10-28T09:58:16.798Z",
"response": {},
"_links": {
"self": {
"href": "https://example.com",
"type": "GET"
}
}
}`), getRequestWithStatus(t, "/tasks/task", 404, ""),
getRequestWithStatus(t, "/tasks/task", 404, ""),
getRequestWithStatus(t, "/tasks/task", 404, ""),
getRequestWithStatus(t, "/tasks/task", 404, ""),
getRequestWithStatus(t, "/tasks/task", 404, ""),
getRequestWithStatus(t, "/tasks/task", 404, "")))
subject, err := clientFromTestServer(s, "key", "secret")
require.NoError(t, err)
err = subject.CloudAccount.Delete(context.TODO(), 1)
var actual *internal.HTTPError
require.True(t, errors.As(err, &actual))
assert.Equal(t, &internal.HTTPError{
Name: "retrieve Task task",
StatusCode: 404,
Body: []byte{},
}, actual)
}