diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dc669b..b70de68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/privatelink_test.go b/privatelink_test.go index 424ecfc..93c2160 100644 --- a/privatelink_test.go +++ b/privatelink_test.go @@ -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" } ], @@ -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{{ @@ -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" } ], @@ -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{{ @@ -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()) + } + }) + } +} diff --git a/service/privatelink/model.go b/service/privatelink/model.go index e99cec0..49d64c3 100644 --- a/service/privatelink/model.go +++ b/service/privatelink/model.go @@ -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"` } diff --git a/service/privatelink/service.go b/service/privatelink/service.go index dcaeed5..c7af6f1 100644 --- a/service/privatelink/service.go +++ b/service/privatelink/service.go @@ -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) @@ -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)