-
Notifications
You must be signed in to change notification settings - Fork 2
/
account_test.go
151 lines (137 loc) · 3.58 KB
/
account_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
package rediscloud_api
import (
"context"
"net/http/httptest"
"testing"
"github.com/RedisLabs/rediscloud-go-api/redis"
"github.com/RedisLabs/rediscloud-go-api/service/account"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAccount_ListPayments(t *testing.T) {
s := httptest.NewServer(testServer("apiKey", "secret", getRequest(t, "/payment-methods", `{
"accountId": 1,
"paymentMethods": [
{
"id": 123,
"type": "Visa",
"creditCardEndsWith": 9876,
"nameOnCard": "Guy Incognito",
"expirationMonth": 1,
"expirationYear": 2021
},
{
"id": 654,
"type": "Mastercard",
"creditCardEndsWith": 4567,
"nameOnCard": "Joey JoJo Junior Shabadoo",
"expirationMonth": 2,
"expirationYear": 2022
}
],
"_links": {
"self": {
"href": "https://example.com",
"type": "GET"
}
}
}`)))
subject, err := clientFromTestServer(s, "apiKey", "secret")
require.NoError(t, err)
actual, err := subject.Account.ListPaymentMethods(context.TODO())
require.NoError(t, err)
assert.ElementsMatch(t, []*account.PaymentMethod{
{
ID: redis.Int(123),
Type: redis.String("Visa"),
CreditCardEndsWith: redis.Int(9876),
ExpirationMonth: redis.Int(1),
ExpirationYear: redis.Int(2021),
},
{
ID: redis.Int(654),
Type: redis.String("Mastercard"),
CreditCardEndsWith: redis.Int(4567),
ExpirationMonth: redis.Int(2),
ExpirationYear: redis.Int(2022),
},
}, actual)
}
func TestAccount_ListRegions(t *testing.T) {
s := httptest.NewServer(testServer("apiKey", "secret", getRequest(t, "/regions", `{
"regions": [
{
"name": "asia-east1",
"provider": "GCP"
},
{
"name": "eu-west-1",
"provider": "AWS"
}
],
"_links": {
"self": {
"href": "https://example.com",
"type": "GET"
}
}
}`)))
subject, err := clientFromTestServer(s, "apiKey", "secret")
require.NoError(t, err)
actual, err := subject.Account.ListRegions(context.TODO())
require.NoError(t, err)
assert.ElementsMatch(t, []*account.Region{
{
Name: redis.String("asia-east1"),
Provider: redis.String("GCP"),
},
{
Name: redis.String("eu-west-1"),
Provider: redis.String("AWS"),
},
}, actual)
}
func TestAccount_ListDatabaseModules(t *testing.T) {
s := httptest.NewServer(testServer("apiKey", "secret", getRequest(t, "/database-modules", `{
"modules": [
{
"name": "RedisBloom",
"description": "Bloom Filter Module for Redis",
"parameters": []
},
{
"name": "RedisGraph",
"description": "A graph database on top of Redis which supports Open-Cypher query language",
"parameters": [
{
"name": "number-of-threads",
"description": "Number of threads used by RedisGraph",
"type": "integer",
"defaultValue": 1,
"required": false
}
]
}
],
"_links": {
"self": {
"href": "https://example.com",
"type": "GET"
}
}
}`)))
subject, err := clientFromTestServer(s, "apiKey", "secret")
require.NoError(t, err)
actual, err := subject.Account.ListDatabaseModules(context.TODO())
require.NoError(t, err)
assert.ElementsMatch(t, []*account.DatabaseModule{
{
Name: redis.String("RedisBloom"),
Description: redis.String("Bloom Filter Module for Redis"),
},
{
Name: redis.String("RedisGraph"),
Description: redis.String("A graph database on top of Redis which supports Open-Cypher query language"),
},
}, actual)
}