Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ConfigCustom in Private Links Create #119

Merged
merged 12 commits into from
Nov 5, 2024
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v1.0.3...HEAD)
## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v1.0.4...HEAD)

## [1.0.4](https://github.com/fivetran/go-fivetran/compare/v1.0.3...v1.0.4)

## Added
- Fix `PrivateLinkCreateService.Do` with `PrivateLinkCreateService.ConfigCustom`

## [1.0.3](https://github.com/fivetran/go-fivetran/compare/v1.0.2...v1.0.3)

Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const defaultBaseURL = "https://api.fivetran.com/v1"
const restAPIv2 = "application/json;version=2"

// WARNING: Update Agent version on each release!
const defaultUserAgent = "Go-Fivetran/1.0.2"
const defaultUserAgent = "Go-Fivetran/1.0.4"

// New receives API Key and API Secret, and returns a new Client with the
// default HTTP client
Expand Down
2 changes: 1 addition & 1 deletion private_link/private_link_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *PrivateLinkCreateService) ConfigCustom(value *map[string]interface{}) *
}

func (s *PrivateLinkCreateService) do(ctx context.Context, req, response any) error {
err := s.HttpService.Do(ctx, "POST", "/private-links", s.request(), nil, 201, &response)
err := s.HttpService.Do(ctx, "POST", "/private-links", req, nil, 201, &response)
return err
}

Expand Down
10 changes: 7 additions & 3 deletions test_utils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"os"
"reflect"
"testing"
"strconv"
"time"
"math/rand"

"github.com/fivetran/go-fivetran"
"github.com/fivetran/go-fivetran/tests/mock"
Expand All @@ -21,6 +23,7 @@ var Client *fivetran.Client

var CertificateHash string
var EncodedCertificate string
var SeededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))

// Tests should be re-written to not use a pre-defined user and group
const (
Expand Down Expand Up @@ -744,12 +747,13 @@ func CreateExternalLogging(t *testing.T) string {
/* Private Links */
func CreatePrivateLink(t *testing.T) string {
t.Helper()
suffix := strconv.Itoa(SeededRand.Int())
created, err := Client.NewPrivateLinkCreate().
Name("go_sdk_private_link_internal").
Service("SOURCE").
Name(suffix).
Service("SOURCE_GCP").
Region("GCP_US_EAST4").
Config(fivetran.NewPrivateLinkConfig().
ConnectionServiceName("test")).
PrivateConnectionServiceId("test")).
Do(context.Background())

if err != nil {
Expand Down
45 changes: 38 additions & 7 deletions tests/e2e/private_link_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ package fivetran_test
import (
"context"
"testing"
"strconv"

"github.com/fivetran/go-fivetran"
testutils "github.com/fivetran/go-fivetran/test_utils"
)

func TestNewPrivateLinkCreateE2E(t *testing.T) {
t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")

t.Skip("Passed in previous runs. Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")
suffix := strconv.Itoa(testutils.SeededRand.Int())
created, err := testutils.Client.NewPrivateLinkCreate().
Name("go_sdk_private_link_test").
Service("SOURCE").
Name(suffix).
Service("SOURCE_GCP").
Region("GCP_US_EAST4").
Config(fivetran.NewPrivateLinkConfig().
ConnectionServiceName("test")).
PrivateConnectionServiceId("test")).
Do(context.Background())

if err != nil {
Expand All @@ -26,13 +27,43 @@ func TestNewPrivateLinkCreateE2E(t *testing.T) {

testutils.AssertEqual(t, created.Code, "Success")
testutils.AssertNotEmpty(t, created.Message)
testutils.AssertEqual(t, created.Data.Name, "go_sdk_private_link_test")
testutils.AssertEqual(t, created.Data.Name, suffix)
testutils.AssertNotEmpty(t, created.Data.Service)
testutils.AssertNotEmpty(t, created.Data.Region)
testutils.AssertNotEmpty(t, created.Data.CloudProvider)
testutils.AssertEqual(t, created.Data.Config.ConnectionServiceName, "test")
testutils.AssertEqual(t, created.Data.Config.PrivateConnectionServiceId, "test")

t.Cleanup(func() {
testutils.DeletePrivateLink(t, created.Data.Id)
})
}

func TestNewPrivateLinkCustomCreateE2E(t *testing.T) {
t.Skip("Passed in previous runs. Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")
suffix := strconv.Itoa(testutils.SeededRand.Int())
created, err := testutils.Client.NewPrivateLinkCreate().
Name(suffix).
Service("SOURCE_GCP").
Region("GCP_US_EAST4").
ConfigCustom(&map[string]interface{}{
"private_connection_service_id": "test",
}).
DoCustom(context.Background())

if err != nil {
t.Logf("%+v\n", created)
t.Error(err)
}

testutils.AssertEqual(t, created.Code, "Success")
testutils.AssertNotEmpty(t, created.Message)
testutils.AssertEqual(t, created.Data.Name, suffix)
testutils.AssertNotEmpty(t, created.Data.Service)
testutils.AssertNotEmpty(t, created.Data.Region)
testutils.AssertNotEmpty(t, created.Data.CloudProvider)
testutils.AssertEqual(t, created.Data.Config["private_connection_service_id"], "test")

t.Cleanup(func() {
testutils.DeletePrivateLink(t, created.Data.Id)
})
}
2 changes: 1 addition & 1 deletion tests/e2e/private_link_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestNewPrivateLinkDeleteE2E(t *testing.T) {
t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")
t.Skip("Passed in previous runs. Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")

privateLinkId := testutils.CreatePrivateLink(t)

Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/private_link_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestPrivateLinkDetailsE2E(t *testing.T) {
t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")
t.Skip("Passed in previous runs. Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")

linkId := testutils.CreatePrivateLink(t)

Expand All @@ -22,8 +22,8 @@ func TestPrivateLinkDetailsE2E(t *testing.T) {
testutils.AssertEqual(t, result.Data.Id, linkId)
testutils.AssertNotEmpty(t, result.Data.Name)
testutils.AssertNotEmpty(t, result.Data.AccountId)
testutils.AssertNotEmpty(t, result.Data.Region)
testutils.AssertNotEmpty(t, result.Data.Service)
testutils.AssertEqual(t, result.Data.Region, "GCP_US_EAST4")
testutils.AssertEqual(t, result.Data.Service, "SOURCE_GCP")
testutils.AssertNotEmpty(t, result.Data.CreatedAt)
testutils.AssertNotEmpty(t, result.Data.CreatedBy)

Expand Down
19 changes: 11 additions & 8 deletions tests/e2e/private_link_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestPrivateLinkListE2E(t *testing.T) {
t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")
//t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")

linkId := testutils.CreatePrivateLink(t)

Expand All @@ -19,13 +19,16 @@ func TestPrivateLinkListE2E(t *testing.T) {
}

testutils.AssertEqual(t, result.Code, "Success")
testutils.AssertEqual(t, result.Data.Items[0].Id, linkId)
testutils.AssertNotEmpty(t, result.Data.Items[0].AccountId)
testutils.AssertNotEmpty(t, result.Data.Items[0].Region)
testutils.AssertNotEmpty(t, result.Data.Items[0].Service)
testutils.AssertNotEmpty(t, result.Data.Items[0].CreatedAt)
testutils.AssertNotEmpty(t, result.Data.Items[0].CreatedBy)
testutils.AssertNotEmpty(t, result.Data.Items[0].Name)
for _, v := range result.Data.Items {
if v.Id == linkId {
testutils.AssertNotEmpty(t, v.AccountId)
testutils.AssertEqual(t, v.Region, "GCP_US_EAST4")
testutils.AssertEqual(t, v.Service, "SOURCE_GCP")
testutils.AssertNotEmpty(t, v.CreatedAt)
testutils.AssertNotEmpty(t, v.CreatedBy)
testutils.AssertNotEmpty(t, v.Name)
}
}

t.Cleanup(func() { testutils.DeletePrivateLink(t, linkId) })
}
12 changes: 7 additions & 5 deletions tests/e2e/private_link_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ import (
)

func TestNewPrivateLinkModifyE2E(t *testing.T) {
t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")
//t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed")

privateLinkId := testutils.CreateTempPrivateLink(t)

details, err := testutils.Client.NewPrivateLinkModify().PrivateLinkId(privateLinkId).
Config(fivetran.NewPrivateLinkConfig().
ConnectionServiceName("test2")).
PrivateConnectionServiceId("test2")).
Do(context.Background())

if err != nil {
t.Logf("%+v\n", details)
t.Error(err)
if details.Code != "IllegalState" {
t.Error(err)
}
}

testutils.AssertEqual(t, details.Code, "Success")
// Private link in CREATING state is not allowed to perform any operation
testutils.AssertEqual(t, details.Code, "IllegalState")
testutils.AssertNotEmpty(t, details.Message)
testutils.AssertEqual(t, details.Data.Config.ConnectionServiceName, "test2")
}
Loading