Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file.
See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/).

## 0.36.4

### Changed:
* Several fields in the PrivateLink connections datatype now have data types aligned with the API.
* Fixed an issue with a malformed URL for the PrivateLink endpoint scripts and added tests

## 0.36.3

### Added:
Expand Down
102 changes: 94 additions & 8 deletions privatelink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func TestGetPrivateLink(t *testing.T) {
"connections": [
{
"associationId": "received",
"connectionId": 144019,
"connectionId": "vpce-con-12345678",
"type": "connection type",
"ownerId": 12312312,
"ownerId": "123456789012",
"associationDate": "2024-07-16T09:26:40.929904847Z"
}
],
Expand Down Expand Up @@ -112,9 +112,9 @@ func TestGetPrivateLink(t *testing.T) {
ShareName: redis.String("share name"),
Connections: []*pl.PrivateLinkConnection{{
AssociationId: redis.String("received"),
ConnectionId: redis.Int(144019),
ConnectionId: redis.String("vpce-con-12345678"),
Type: redis.String("connection type"),
OwnerId: redis.Int(12312312),
OwnerId: redis.String("123456789012"),
AssociationDate: redis.String("2024-07-16T09:26:40.929904847Z"),
}},
Databases: []*pl.PrivateLinkDatabase{{
Expand Down Expand Up @@ -272,9 +272,9 @@ func TestGetActiveActivePrivateLink(t *testing.T) {
"connections": [
{
"associationId": "received",
"connectionId": 144019,
"connectionId": "vpce-con-12345678",
"type": "connection type",
"ownerId": 12312312,
"ownerId": "123456789012",
"associationDate": "2024-07-16T09:26:40.929904847Z"
}
],
Expand Down Expand Up @@ -316,9 +316,9 @@ func TestGetActiveActivePrivateLink(t *testing.T) {
ShareName: redis.String("share name"),
Connections: []*pl.PrivateLinkConnection{{
AssociationId: redis.String("received"),
ConnectionId: redis.Int(144019),
ConnectionId: redis.String("vpce-con-12345678"),
Type: redis.String("connection type"),
OwnerId: redis.Int(12312312),
OwnerId: redis.String("123456789012"),
AssociationDate: redis.String("2024-07-16T09:26:40.929904847Z"),
}},
Databases: []*pl.PrivateLinkDatabase{{
Expand Down Expand Up @@ -419,3 +419,89 @@ func TestGetActiveActivePrivateLink(t *testing.T) {
})
}
}

func TestGetPrivateLinkScript(t *testing.T) {
t.Skipf("skipping test until privatelink script is available")

tc := []struct {
description string
mockedResponse []endpointRequest
expectedResult *pl.PrivateLinkEndpointScript
expectedError error
expectedErrorAs error
}{
{
description: "should successfully return a privatelink script",
mockedResponse: []endpointRequest{
getRequest(
t,
"/subscriptions/114019/private-link/endpoint-script?includeTerraformAwsScript=true",
`a pro privatelink aws terraform endpoint script`,
),
},
expectedResult: redis.String("a pro privatelink aws terraform endpoint script"),
},
}
for _, testCase := range tc {

t.Run(testCase.description, func(t *testing.T) {
server := httptest.NewServer(
testServer("key", "secret", testCase.mockedResponse...))

subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)

actual, err := subject.PrivateLink.GetPrivateLinkEndpointScript(context.TODO(), 114019)
if testCase.expectedError == nil {
assert.NoError(t, err)
assert.Equal(t, testCase.expectedResult, actual)
} else {
assert.IsType(t, err, testCase.expectedErrorAs)
assert.EqualError(t, err, testCase.expectedError.Error())
}
})
}
}

func TestGetActiveActivePrivateLinkScript(t *testing.T) {
t.Skipf("skipping test until privatelink script is available")

tc := []struct {
description string
mockedResponse []endpointRequest
expectedResult *pl.PrivateLinkEndpointScript
expectedError error
expectedErrorAs error
}{
{
description: "should successfully return an active active privatelink script",
mockedResponse: []endpointRequest{
getRequest(
t,
"/subscriptions/114019/regions/1/private-link/endpoint-script?includeTerraformAwsScript=true",
`an active active aws terraform endpoint script`,
),
},
expectedResult: redis.String("an active active aws terraform endpoint script"),
},
}
for _, testCase := range tc {

t.Run(testCase.description, func(t *testing.T) {
server := httptest.NewServer(
testServer("key", "secret", testCase.mockedResponse...))

subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)

actual, err := subject.PrivateLink.GetActiveActivePrivateLinkEndpointScript(context.TODO(), 114019, 1)
if testCase.expectedError == nil {
assert.NoError(t, err)
assert.Equal(t, testCase.expectedResult, actual)
} else {
assert.IsType(t, err, testCase.expectedErrorAs)
assert.EqualError(t, err, testCase.expectedError.Error())
}
})
}
}
4 changes: 2 additions & 2 deletions service/privatelink/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ type PrivateLinkPrincipal struct {

type PrivateLinkConnection struct {
AssociationId *string `json:"associationId,omitempty"`
ConnectionId *int `json:"connectionId,omitempty"`
ConnectionId *string `json:"connectionId,omitempty"`
Type *string `json:"type,omitempty"`
OwnerId *int `json:"ownerId,omitempty"`
OwnerId *string `json:"ownerId,omitempty"`
AssociationDate *string `json:"associationDate,omitempty"`
}

Expand Down
4 changes: 2 additions & 2 deletions service/privatelink/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type PrivateLinkEndpointScript = string
// GetPrivateLinkEndpointScript will get the script for an endpoint.
func (a *API) GetPrivateLinkEndpointScript(ctx context.Context, subscriptionId int) (*PrivateLinkEndpointScript, error) {
message := fmt.Sprintf("get private link for subscription %d", subscriptionId)
path := fmt.Sprintf("/subscriptions/%d/private-link/endpoint-script/?includeTerraformAwsScript=true", subscriptionId)
path := fmt.Sprintf("/subscriptions/%d/private-link/endpoint-script?includeTerraformAwsScript=true", subscriptionId)
task, err := a.getScript(ctx, message, path)
if err != nil {
return nil, wrap404Error(subscriptionId, err)
Expand Down Expand Up @@ -127,7 +127,7 @@ func (a *API) GetActiveActivePrivateLink(ctx context.Context, subscription int,
// GetPrivateLinkEndpointScript will get the script for an endpoint.
func (a *API) GetActiveActivePrivateLinkEndpointScript(ctx context.Context, subscription int, regionId int) (*PrivateLinkEndpointScript, error) {
message := fmt.Sprintf("get private link for subscription %d", subscription)
path := fmt.Sprintf("/subscriptions/%d/regions/%d/private-link/endpoint-script/?includeTerraformAwsScript=true", subscription, regionId)
path := fmt.Sprintf("/subscriptions/%d/regions/%d/private-link/endpoint-script?includeTerraformAwsScript=true", subscription, regionId)
task, err := a.getScript(ctx, message, path)
if err != nil {
return nil, wrap404Error(subscription, err)
Expand Down