@@ -83,7 +83,6 @@ func TestGetPrivateLink(t *testing.T) {
83
83
}
84
84
],
85
85
"subscriptionId": 114019,
86
- "regionId": 12312312,
87
86
"errorMessage": "no error"
88
87
}
89
88
},
@@ -124,7 +123,6 @@ func TestGetPrivateLink(t *testing.T) {
124
123
ResourceLinkEndpoint : redis .String ("" ),
125
124
}},
126
125
SubscriptionId : redis .Int (114019 ),
127
- RegionId : redis .Int (12312312 ),
128
126
ErrorMessage : redis .String ("no error" ),
129
127
},
130
128
},
@@ -175,7 +173,7 @@ func TestGetPrivateLink(t *testing.T) {
175
173
}` ,
176
174
),
177
175
},
178
- expectedError : errors .New ("resource not found - subscription 114019" ),
176
+ expectedError : errors .New ("privatelink resource not found - subscription 114019" ),
179
177
expectedErrorAs : & pl.NotFound {},
180
178
},
181
179
{
@@ -192,7 +190,7 @@ func TestGetPrivateLink(t *testing.T) {
192
190
"path" : "/v1/subscriptions/114019/private-link"
193
191
}` ),
194
192
},
195
- expectedError : errors .New ("resource not found - subscription 114019" ),
193
+ expectedError : errors .New ("privatelink resource not found - subscription 114019" ),
196
194
expectedErrorAs : & pl.NotFound {},
197
195
},
198
196
}
@@ -216,3 +214,276 @@ func TestGetPrivateLink(t *testing.T) {
216
214
})
217
215
}
218
216
}
217
+
218
+ func TestGetActiveActivePrivateLink (t * testing.T ) {
219
+ tc := []struct {
220
+ description string
221
+ mockedResponse []endpointRequest
222
+ expectedResult * pl.PrivateLink
223
+ expectedError error
224
+ expectedErrorAs error
225
+ }{
226
+ {
227
+ description : "should successfully return an active active privatelink config" ,
228
+ mockedResponse : []endpointRequest {
229
+ getRequest (
230
+ t ,
231
+ "/subscriptions/114019/regions/1/private-link" ,
232
+ `{
233
+ "taskId": "502fc31f-fd44-4cb0-a429-07882309a971",
234
+ "commandType": "activeActivePrivateLinkGetRequest",
235
+ "status": "received",
236
+ "description": "Task request received and is being queued for processing.",
237
+ "timestamp": "2024-07-16T09:26:40.929904847Z",
238
+ "links": [
239
+ {
240
+ "href": "https://api-staging.qa.redislabs.com/v1/tasks/502fc31f-fd44-4cb0-a429-07882309a971",
241
+ "rel": "task",
242
+ "type": "GET"
243
+ }
244
+ ]
245
+ }` ,
246
+ ),
247
+ getRequest (
248
+ t ,
249
+ "/tasks/502fc31f-fd44-4cb0-a429-07882309a971" ,
250
+ `{
251
+ "taskId": "502fc31f-fd44-4cb0-a429-07882309a971",
252
+ "commandType": "activeActivePrivateLinkGetRequest",
253
+ "status": "processing-completed",
254
+ "description": "Request processing completed successfully and its resources are now being provisioned / de-provisioned.",
255
+ "timestamp": "2024-07-16T09:26:49.847808891Z",
256
+ "response": {
257
+ "resourceId": 114019,
258
+ "resource": {
259
+ "status": "received",
260
+ "principals": [
261
+ {
262
+ "principal": "arn:aws:iam::123456789012:root",
263
+ "status": "ready",
264
+ "alias": "some alias",
265
+ "type": "aws_account"
266
+ }
267
+ ],
268
+ "resourceConfigurationId": "123456789012",
269
+ "resourceConfigurationArn": "arn:aws:iam::123456789012:root",
270
+ "shareArn": "arn:aws:iam::123456789012:root",
271
+ "shareName": "share name",
272
+ "connections": [
273
+ {
274
+ "associationId": "received",
275
+ "connectionId": 144019,
276
+ "type": "connection type",
277
+ "ownerId": 12312312,
278
+ "associationDate": "2024-07-16T09:26:40.929904847Z"
279
+ }
280
+ ],
281
+ "databases": [
282
+ {
283
+ "databaseId": 0,
284
+ "port": 6379,
285
+ "rlEndpoint": ""
286
+ }
287
+ ],
288
+ "subscriptionId": 114019,
289
+ "regionId": 1,
290
+ "errorMessage": "no error"
291
+ }
292
+ },
293
+ "links": [
294
+ {
295
+ "href": "https://api-staging.qa.redislabs.com/v1/tasks/502fc31f-fd44-4cb0-a429-07882309a971",
296
+ "rel": "self",
297
+ "type": "GET"
298
+ }
299
+ ]
300
+ }` ,
301
+ ),
302
+ },
303
+ expectedResult : & pl.PrivateLink {
304
+ Status : redis .String ("received" ),
305
+ Principals : []* pl.PrivateLinkPrincipal {
306
+ {
307
+ Principal : redis .String ("arn:aws:iam::123456789012:root" ),
308
+ Status : redis .String ("ready" ),
309
+ Alias : redis .String ("some alias" ),
310
+ Type : redis .String ("aws_account" ),
311
+ },
312
+ },
313
+ ResourceConfigurationId : redis .String ("123456789012" ),
314
+ ResourceConfigurationArn : redis .String ("arn:aws:iam::123456789012:root" ),
315
+ ShareArn : redis .String ("arn:aws:iam::123456789012:root" ),
316
+ ShareName : redis .String ("share name" ),
317
+ Connections : []* pl.PrivateLinkConnection {{
318
+ AssociationId : redis .String ("received" ),
319
+ ConnectionId : redis .Int (144019 ),
320
+ Type : redis .String ("connection type" ),
321
+ OwnerId : redis .Int (12312312 ),
322
+ AssociationDate : redis .String ("2024-07-16T09:26:40.929904847Z" ),
323
+ }},
324
+ Databases : []* pl.PrivateLinkDatabase {{
325
+ DatabaseId : redis .Int (0 ),
326
+ Port : redis .Int (6379 ),
327
+ ResourceLinkEndpoint : redis .String ("" ),
328
+ }},
329
+ SubscriptionId : redis .Int (114019 ),
330
+ RegionId : redis .Int (1 ),
331
+ ErrorMessage : redis .String ("no error" ),
332
+ },
333
+ },
334
+ {
335
+ description : "should fail when private link is not found" ,
336
+ mockedResponse : []endpointRequest {
337
+ getRequest (
338
+ t ,
339
+ "/subscriptions/114019/regions/1/private-link" ,
340
+ `{
341
+ "taskId": "502fc31f-fd44-4cb0-a429-07882309a971",
342
+ "commandType": "activeActivePrivateLinkGetRequest",
343
+ "status": "received",
344
+ "description": "Task request received and is being queued for processing.",
345
+ "timestamp": "2024-07-16T09:26:40.929904847Z",
346
+ "links": [
347
+ {
348
+ "href": "https://api-staging.qa.redislabs.com/v1/tasks/502fc31f-fd44-4cb0-a429-07882309a971",
349
+ "rel": "task",
350
+ "type": "GET"
351
+ }
352
+ ]
353
+ }` ,
354
+ ),
355
+ getRequest (
356
+ t ,
357
+ "/tasks/502fc31f-fd44-4cb0-a429-07882309a971" ,
358
+ `{
359
+ "taskId": "502fc31f-fd44-4cb0-a429-07882309a971",
360
+ "commandType": "activeActivePrivateLinkGetRequest",
361
+ "status": "processing-error",
362
+ "description": "Task request failed during processing. See error information for failure details.",
363
+ "timestamp": "2025-01-13T11:22:51.204189721Z",
364
+ "response": {
365
+ "error": {
366
+ "type": "PRIVATELINK_SERVICE_NOT_FOUND",
367
+ "status": "404 NOT_FOUND",
368
+ "description": "Private Service Connect service not found"
369
+ }
370
+ },
371
+ "links": [
372
+ {
373
+ "href": "https://api-staging.qa.redislabs.com/v1/tasks/502fc31f-fd44-4cb0-a429-07882309a971",
374
+ "rel": "self",
375
+ "type": "GET"
376
+ }
377
+ ]
378
+ }` ,
379
+ ),
380
+ },
381
+ expectedError : errors .New ("privatelink resource not found - subscription 114019" ),
382
+ expectedErrorAs : & pl.NotFound {},
383
+ },
384
+ {
385
+ description : "should fail when subscription is not found" ,
386
+ mockedResponse : []endpointRequest {
387
+ getRequestWithStatus (
388
+ t ,
389
+ "/subscriptions/114019/regions/1/private-link" ,
390
+ 404 ,
391
+ `{
392
+ "timestamp" : "2025-01-17T09:34:25.803+00:00",
393
+ "status" : 404,
394
+ "error" : "Not Found",
395
+ "path" : "/v1/subscriptions/114019/regions/1/private-link"
396
+ }` ),
397
+ },
398
+ expectedError : errors .New ("privatelink resource not found - subscription 114019" ),
399
+ expectedErrorAs : & pl.NotFound {},
400
+ },
401
+ }
402
+
403
+ for _ , testCase := range tc {
404
+ t .Run (testCase .description , func (t * testing.T ) {
405
+ server := httptest .NewServer (
406
+ testServer ("key" , "secret" , testCase .mockedResponse ... ))
407
+
408
+ subject , err := clientFromTestServer (server , "key" , "secret" )
409
+ require .NoError (t , err )
410
+
411
+ actual , err := subject .PrivateLink .GetActiveActivePrivateLink (context .TODO (), 114019 , 1 )
412
+ if testCase .expectedError == nil {
413
+ assert .NoError (t , err )
414
+ assert .Equal (t , testCase .expectedResult , actual )
415
+ } else {
416
+ assert .IsType (t , err , testCase .expectedErrorAs )
417
+ assert .EqualError (t , err , testCase .expectedError .Error ())
418
+ }
419
+ })
420
+ }
421
+ }
422
+
423
+ //func TestCreatePrivateLink(t *testing.T) {
424
+ // expected := 114019
425
+ // server := httptest.NewServer(
426
+ // testServer(
427
+ // "key",
428
+ // "secret",
429
+ // postRequest(
430
+ // t,
431
+ // "/subscriptions/114019/private-link",
432
+ // `{
433
+ // "alias": "test",
434
+ // "principal": "123456789012"
435
+ // "shareName": "testshare"
436
+ // "type": "aws-account"
437
+ // }`,
438
+ // `{
439
+ // "taskId": "abcd-efgh-ijkl-mnop",
440
+ // "commandType": "privateLinkCreateRequest",
441
+ // "status": "received",
442
+ // "description": "Task request received and is being queued for processing.",
443
+ // "timestamp": "2025-09-18T15:56:00Z",
444
+ // "links": [
445
+ // {
446
+ // "rel": "task",
447
+ // "href": "https://api-staging.qa.redislabs.com/v1/tasks/abcd-efgh-ijkl-mnop",
448
+ // "title": "getTaskStatusUpdates",
449
+ // "type": "GET"
450
+ // }
451
+ // ]
452
+ // }`,
453
+ // ),
454
+ // getRequest(
455
+ // t,
456
+ // "/tasks/abcd-efgh-ijkl-mnop",
457
+ // fmt.Sprintf(`{
458
+ // "taskId": "abcd-efgh-ijkl-mnop",
459
+ // "commandType": "privateLinkCreateRequest",
460
+ // "status": "processing-completed",
461
+ // "description": "Request processing completed successfully.",
462
+ // "timestamp": "2025-09-18T15:56:10Z",
463
+ // "response": {
464
+ // "resourceId": %[1]d
465
+ // },
466
+ // "links": [
467
+ // {
468
+ // "href": "https://api-staging.qa.redislabs.com/v1/tasks/502fc31f-fd44-4cb0-a429-07882309a971",
469
+ // "rel": "self",
470
+ // "type": "GET"
471
+ // }
472
+ // ]
473
+ // }`, expected),
474
+ // ),
475
+ // ),
476
+ // )
477
+ //
478
+ // subject, err := clientFromTestServer(server, "key", "secret")
479
+ // require.NoError(t, err)
480
+ //
481
+ // actual, err := subject.PrivateLink.CreatePrivateLink(context.TODO(), 114019, pl.CreatePrivateLink{
482
+ // ShareName: redis.String("testshare"),
483
+ // Principal: redis.String("12345679012"),
484
+ // PrincipalType: redis.String("aws-account"),
485
+ // PrincipalAlias: redis.String("test"),
486
+ // })
487
+ // require.NoError(t, err)
488
+ // assert.Equal(t, expected, actual)
489
+ //}
0 commit comments