Skip to content

Commit 2ec2487

Browse files
Merge pull request #230 from RedisLabs/fix/fixing-pending-delete
Datatype alignment, endpoint script fix
2 parents 667fcf5 + 1f62793 commit 2ec2487

File tree

4 files changed

+104
-12
lines changed

4 files changed

+104
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
All notable changes to this project will be documented in this file.
33
See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/).
44

5+
## 0.36.4
6+
7+
### Changed:
8+
* Several fields in the PrivateLink connections datatype now have data types aligned with the API.
9+
* Fixed an issue with a malformed URL for the PrivateLink endpoint scripts and added tests
10+
511
## 0.36.3
612

713
### Added:

privatelink_test.go

Lines changed: 94 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ func TestGetPrivateLink(t *testing.T) {
6969
"connections": [
7070
{
7171
"associationId": "received",
72-
"connectionId": 144019,
72+
"connectionId": "vpce-con-12345678",
7373
"type": "connection type",
74-
"ownerId": 12312312,
74+
"ownerId": "123456789012",
7575
"associationDate": "2024-07-16T09:26:40.929904847Z"
7676
}
7777
],
@@ -112,9 +112,9 @@ func TestGetPrivateLink(t *testing.T) {
112112
ShareName: redis.String("share name"),
113113
Connections: []*pl.PrivateLinkConnection{{
114114
AssociationId: redis.String("received"),
115-
ConnectionId: redis.Int(144019),
115+
ConnectionId: redis.String("vpce-con-12345678"),
116116
Type: redis.String("connection type"),
117-
OwnerId: redis.Int(12312312),
117+
OwnerId: redis.String("123456789012"),
118118
AssociationDate: redis.String("2024-07-16T09:26:40.929904847Z"),
119119
}},
120120
Databases: []*pl.PrivateLinkDatabase{{
@@ -272,9 +272,9 @@ func TestGetActiveActivePrivateLink(t *testing.T) {
272272
"connections": [
273273
{
274274
"associationId": "received",
275-
"connectionId": 144019,
275+
"connectionId": "vpce-con-12345678",
276276
"type": "connection type",
277-
"ownerId": 12312312,
277+
"ownerId": "123456789012",
278278
"associationDate": "2024-07-16T09:26:40.929904847Z"
279279
}
280280
],
@@ -316,9 +316,9 @@ func TestGetActiveActivePrivateLink(t *testing.T) {
316316
ShareName: redis.String("share name"),
317317
Connections: []*pl.PrivateLinkConnection{{
318318
AssociationId: redis.String("received"),
319-
ConnectionId: redis.Int(144019),
319+
ConnectionId: redis.String("vpce-con-12345678"),
320320
Type: redis.String("connection type"),
321-
OwnerId: redis.Int(12312312),
321+
OwnerId: redis.String("123456789012"),
322322
AssociationDate: redis.String("2024-07-16T09:26:40.929904847Z"),
323323
}},
324324
Databases: []*pl.PrivateLinkDatabase{{
@@ -419,3 +419,89 @@ func TestGetActiveActivePrivateLink(t *testing.T) {
419419
})
420420
}
421421
}
422+
423+
func TestGetPrivateLinkScript(t *testing.T) {
424+
t.Skipf("skipping test until privatelink script is available")
425+
426+
tc := []struct {
427+
description string
428+
mockedResponse []endpointRequest
429+
expectedResult *pl.PrivateLinkEndpointScript
430+
expectedError error
431+
expectedErrorAs error
432+
}{
433+
{
434+
description: "should successfully return a privatelink script",
435+
mockedResponse: []endpointRequest{
436+
getRequest(
437+
t,
438+
"/subscriptions/114019/private-link/endpoint-script?includeTerraformAwsScript=true",
439+
`a pro privatelink aws terraform endpoint script`,
440+
),
441+
},
442+
expectedResult: redis.String("a pro privatelink aws terraform endpoint script"),
443+
},
444+
}
445+
for _, testCase := range tc {
446+
447+
t.Run(testCase.description, func(t *testing.T) {
448+
server := httptest.NewServer(
449+
testServer("key", "secret", testCase.mockedResponse...))
450+
451+
subject, err := clientFromTestServer(server, "key", "secret")
452+
require.NoError(t, err)
453+
454+
actual, err := subject.PrivateLink.GetPrivateLinkEndpointScript(context.TODO(), 114019)
455+
if testCase.expectedError == nil {
456+
assert.NoError(t, err)
457+
assert.Equal(t, testCase.expectedResult, actual)
458+
} else {
459+
assert.IsType(t, err, testCase.expectedErrorAs)
460+
assert.EqualError(t, err, testCase.expectedError.Error())
461+
}
462+
})
463+
}
464+
}
465+
466+
func TestGetActiveActivePrivateLinkScript(t *testing.T) {
467+
t.Skipf("skipping test until privatelink script is available")
468+
469+
tc := []struct {
470+
description string
471+
mockedResponse []endpointRequest
472+
expectedResult *pl.PrivateLinkEndpointScript
473+
expectedError error
474+
expectedErrorAs error
475+
}{
476+
{
477+
description: "should successfully return an active active privatelink script",
478+
mockedResponse: []endpointRequest{
479+
getRequest(
480+
t,
481+
"/subscriptions/114019/regions/1/private-link/endpoint-script?includeTerraformAwsScript=true",
482+
`an active active aws terraform endpoint script`,
483+
),
484+
},
485+
expectedResult: redis.String("an active active aws terraform endpoint script"),
486+
},
487+
}
488+
for _, testCase := range tc {
489+
490+
t.Run(testCase.description, func(t *testing.T) {
491+
server := httptest.NewServer(
492+
testServer("key", "secret", testCase.mockedResponse...))
493+
494+
subject, err := clientFromTestServer(server, "key", "secret")
495+
require.NoError(t, err)
496+
497+
actual, err := subject.PrivateLink.GetActiveActivePrivateLinkEndpointScript(context.TODO(), 114019, 1)
498+
if testCase.expectedError == nil {
499+
assert.NoError(t, err)
500+
assert.Equal(t, testCase.expectedResult, actual)
501+
} else {
502+
assert.IsType(t, err, testCase.expectedErrorAs)
503+
assert.EqualError(t, err, testCase.expectedError.Error())
504+
}
505+
})
506+
}
507+
}

service/privatelink/model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ type PrivateLinkPrincipal struct {
3232

3333
type PrivateLinkConnection struct {
3434
AssociationId *string `json:"associationId,omitempty"`
35-
ConnectionId *int `json:"connectionId,omitempty"`
35+
ConnectionId *string `json:"connectionId,omitempty"`
3636
Type *string `json:"type,omitempty"`
37-
OwnerId *int `json:"ownerId,omitempty"`
37+
OwnerId *string `json:"ownerId,omitempty"`
3838
AssociationDate *string `json:"associationDate,omitempty"`
3939
}
4040

service/privatelink/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type PrivateLinkEndpointScript = string
6666
// GetPrivateLinkEndpointScript will get the script for an endpoint.
6767
func (a *API) GetPrivateLinkEndpointScript(ctx context.Context, subscriptionId int) (*PrivateLinkEndpointScript, error) {
6868
message := fmt.Sprintf("get private link for subscription %d", subscriptionId)
69-
path := fmt.Sprintf("/subscriptions/%d/private-link/endpoint-script/?includeTerraformAwsScript=true", subscriptionId)
69+
path := fmt.Sprintf("/subscriptions/%d/private-link/endpoint-script?includeTerraformAwsScript=true", subscriptionId)
7070
task, err := a.getScript(ctx, message, path)
7171
if err != nil {
7272
return nil, wrap404Error(subscriptionId, err)
@@ -127,7 +127,7 @@ func (a *API) GetActiveActivePrivateLink(ctx context.Context, subscription int,
127127
// GetPrivateLinkEndpointScript will get the script for an endpoint.
128128
func (a *API) GetActiveActivePrivateLinkEndpointScript(ctx context.Context, subscription int, regionId int) (*PrivateLinkEndpointScript, error) {
129129
message := fmt.Sprintf("get private link for subscription %d", subscription)
130-
path := fmt.Sprintf("/subscriptions/%d/regions/%d/private-link/endpoint-script/?includeTerraformAwsScript=true", subscription, regionId)
130+
path := fmt.Sprintf("/subscriptions/%d/regions/%d/private-link/endpoint-script?includeTerraformAwsScript=true", subscription, regionId)
131131
task, err := a.getScript(ctx, message, path)
132132
if err != nil {
133133
return nil, wrap404Error(subscription, err)

0 commit comments

Comments
 (0)