@@ -2,6 +2,8 @@ package rediscloud_api
22
33import (
44 "context"
5+ "fmt"
6+ "net/http"
57 "net/http/httptest"
68 "testing"
79 "time"
@@ -12,6 +14,244 @@ import (
1214 "github.com/stretchr/testify/require"
1315)
1416
17+ func TestAADatabase_Create (t * testing.T ) {
18+ expected := 1466
19+ s := httptest .NewServer (testServer ("key" , "secret" , postRequest (t , "/subscriptions/111478/databases" , `{
20+ "dryRun": false,
21+ "name": "active-active-example",
22+ "protocol": "redis",
23+ "memoryLimitInGb": 1,
24+ "datasetSizeInGb": 1,
25+ "supportOSSClusterApi": false,
26+ "respVersion": "resp3",
27+ "useExternalEndpointForOSSClusterApi": false,
28+ "dataEvictionPolicy": "noeviction",
29+ "dataPersistence": "none",
30+ "sourceIp": [
31+ "0.0.0.0/0"
32+ ],
33+ "password": "test-password",
34+ "alerts": [
35+ {
36+ "name": "dataset-size",
37+ "value": 80
38+ }
39+ ],
40+ "modules": [
41+ {
42+ "name": "RedisJSON"
43+ }
44+ ],
45+ "localThroughputMeasurement": [
46+ {
47+ "region": "us-east-1",
48+ "writeOperationsPerSecond": 1000,
49+ "readOperationsPerSecond": 1000
50+ },
51+ {
52+ "region": "us-east-2",
53+ "writeOperationsPerSecond": 1000,
54+ "readOperationsPerSecond": 1000
55+ }
56+ ],
57+ "port": 12000,
58+ "queryPerformanceFactor": "Standard",
59+ "redisVersion": "7.2"
60+ }` , `{
61+ "taskId": "task",
62+ "commandType": "databaseCreateRequest",
63+ "status": "received",
64+ "description": "Task request received and is being queued for processing.",
65+ "timestamp": "2024-05-08T08:10:02Z",
66+ "_links": {
67+ "task": {
68+ "href": "https://example.org",
69+ "title": "getTaskStatusUpdates",
70+ "type": "GET"
71+ }
72+ }
73+ }` ), getRequest (t , "/tasks/task" , fmt .Sprintf (`{
74+ "taskId": "task",
75+ "commandType": "databaseCreateRequest",
76+ "status": "processing-completed",
77+ "timestamp": "2024-05-08T08:22:34Z",
78+ "response": {
79+ "resourceId": %d
80+ },
81+ "_links": {
82+ "self": {
83+ "href": "https://example.com",
84+ "type": "GET"
85+ }
86+ }
87+ }` , expected ))))
88+
89+ subject , err := clientFromTestServer (s , "key" , "secret" )
90+ require .NoError (t , err )
91+
92+ actual , err := subject .Database .ActiveActiveCreate (context .TODO (), 111478 , databases.CreateActiveActiveDatabase {
93+ DryRun : redis .Bool (false ),
94+ Name : redis .String ("active-active-example" ),
95+ Protocol : redis .String ("redis" ),
96+ MemoryLimitInGB : redis .Float64 (1 ),
97+ DatasetSizeInGB : redis .Float64 (1 ),
98+ SupportOSSClusterAPI : redis .Bool (false ),
99+ RespVersion : redis .String ("resp3" ),
100+ UseExternalEndpointForOSSClusterAPI : redis .Bool (false ),
101+ DataEvictionPolicy : redis .String ("noeviction" ),
102+ GlobalDataPersistence : redis .String ("none" ),
103+ GlobalSourceIP : redis .StringSlice ("0.0.0.0/0" ),
104+ GlobalPassword : redis .String ("test-password" ),
105+ GlobalAlerts : []* databases.Alert {
106+ {
107+ Name : redis .String ("dataset-size" ),
108+ Value : redis .Int (80 ),
109+ },
110+ },
111+ GlobalModules : []* databases.Module {
112+ {
113+ Name : redis .String ("RedisJSON" ),
114+ },
115+ },
116+ LocalThroughputMeasurement : []* databases.LocalThroughput {
117+ {
118+ Region : redis .String ("us-east-1" ),
119+ WriteOperationsPerSecond : redis .Int (1000 ),
120+ ReadOperationsPerSecond : redis .Int (1000 ),
121+ },
122+ {
123+ Region : redis .String ("us-east-2" ),
124+ WriteOperationsPerSecond : redis .Int (1000 ),
125+ ReadOperationsPerSecond : redis .Int (1000 ),
126+ },
127+ },
128+ PortNumber : redis .Int (12000 ),
129+ QueryPerformanceFactor : redis .String ("Standard" ),
130+ RedisVersion : redis .String ("7.2" ),
131+ })
132+ require .NoError (t , err )
133+
134+ assert .Equal (t , expected , actual )
135+ }
136+
137+ func TestAADatabase_Update (t * testing.T ) {
138+ flow := taskFlow (
139+ t ,
140+ http .MethodPut ,
141+ "/subscriptions/111478/databases/1466/regions" ,
142+ `{
143+ "dryRun": false,
144+ "memoryLimitInGb": 2,
145+ "datasetSizeInGb": 2,
146+ "supportOSSClusterApi": false,
147+ "useExternalEndpointForOSSClusterApi": false,
148+ "clientSslCertificate": "cert-content",
149+ "clientTlsCertificates": ["cert1", "cert2"],
150+ "enableTls": true,
151+ "globalDataPersistence": "aof-every-1-second",
152+ "globalPassword": "new-password",
153+ "globalEnableDefaultUser": true,
154+ "globalSourceIp": [
155+ "192.168.1.0/24"
156+ ],
157+ "globalAlerts": [
158+ {
159+ "name": "throughput-higher-than",
160+ "value": 90
161+ }
162+ ],
163+ "regions": [
164+ {
165+ "region": "us-east-1",
166+ "remoteBackup": {
167+ "active": true,
168+ "interval": "every-12-hours",
169+ "timeUTC": "10:00",
170+ "storageType": "aws-s3",
171+ "storagePath": "s3://bucket/path"
172+ },
173+ "localThroughputMeasurement": {
174+ "writeOperationsPerSecond": 2000,
175+ "readOperationsPerSecond": 2000
176+ },
177+ "dataPersistence": "aof-every-1-second",
178+ "password": "region-password",
179+ "sourceIp": [
180+ "10.0.0.0/8"
181+ ],
182+ "enableDefaultUser": false,
183+ "alerts": [
184+ {
185+ "name": "dataset-size",
186+ "value": 85
187+ }
188+ ]
189+ }
190+ ],
191+ "dataEvictionPolicy": "allkeys-lru",
192+ "queryPerformanceFactor": "6x"
193+ }` ,
194+ "update-task" ,
195+ "databaseUpdateRequest" ,
196+ )
197+
198+ s := httptest .NewServer (testServer ("key" , "secret" , flow ... ))
199+ defer s .Close ()
200+
201+ subject , err := clientFromTestServer (s , "key" , "secret" )
202+ require .NoError (t , err )
203+
204+ err = subject .Database .ActiveActiveUpdate (context .TODO (), 111478 , 1466 , databases.UpdateActiveActiveDatabase {
205+ DryRun : redis .Bool (false ),
206+ MemoryLimitInGB : redis .Float64 (2 ),
207+ DatasetSizeInGB : redis .Float64 (2 ),
208+ SupportOSSClusterAPI : redis .Bool (false ),
209+ UseExternalEndpointForOSSClusterAPI : redis .Bool (false ),
210+ ClientSSLCertificate : redis .String ("cert-content" ),
211+ ClientTLSCertificates : & []* string {redis .String ("cert1" ), redis .String ("cert2" )},
212+ EnableTls : redis .Bool (true ),
213+ GlobalDataPersistence : redis .String ("aof-every-1-second" ),
214+ GlobalPassword : redis .String ("new-password" ),
215+ GlobalEnableDefaultUser : redis .Bool (true ),
216+ GlobalSourceIP : redis .StringSlice ("192.168.1.0/24" ),
217+ GlobalAlerts : & []* databases.Alert {
218+ {
219+ Name : redis .String ("throughput-higher-than" ),
220+ Value : redis .Int (90 ),
221+ },
222+ },
223+ Regions : []* databases.LocalRegionProperties {
224+ {
225+ Region : redis .String ("us-east-1" ),
226+ RemoteBackup : & databases.DatabaseBackupConfig {
227+ Active : redis .Bool (true ),
228+ Interval : redis .String ("every-12-hours" ),
229+ TimeUTC : redis .String ("10:00" ),
230+ StorageType : redis .String ("aws-s3" ),
231+ StoragePath : redis .String ("s3://bucket/path" ),
232+ },
233+ LocalThroughputMeasurement : & databases.LocalThroughput {
234+ WriteOperationsPerSecond : redis .Int (2000 ),
235+ ReadOperationsPerSecond : redis .Int (2000 ),
236+ },
237+ DataPersistence : redis .String ("aof-every-1-second" ),
238+ Password : redis .String ("region-password" ),
239+ SourceIP : redis .StringSlice ("10.0.0.0/8" ),
240+ EnableDefaultUser : redis .Bool (false ),
241+ Alerts : & []* databases.Alert {
242+ {
243+ Name : redis .String ("dataset-size" ),
244+ Value : redis .Int (85 ),
245+ },
246+ },
247+ },
248+ },
249+ DataEvictionPolicy : redis .String ("allkeys-lru" ),
250+ QueryPerformanceFactor : redis .String ("6x" ),
251+ })
252+ require .NoError (t , err )
253+ }
254+
15255func TestAADatabase_List (t * testing.T ) {
16256 body := `{
17257 "accountId": 69369,
0 commit comments