Skip to content

Commit

Permalink
Fix columns list response model (#108)
Browse files Browse the repository at this point in the history
* Fix columns list response model

* Support  for table
  • Loading branch information
beevital authored Jun 21, 2024
1 parent 2a94b66 commit bd04085
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 95 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ 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/v0.8.7...HEAD)
## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v0.8.8...HEAD)

## [0.8.8](https://github.com/fivetran/go-fivetran/compare/v0.8.7...v0.8.8)

## Fixed
- Response model for [Retrieve Source Table Columns Config](https://fivetran.com/docs/rest-api/connectors#retrievesourcetablecolumnsconfig) fixed.

## Added
- New field `connectors.ConnectorSchemaConfigTableResponse.SupportsColumnsConfig` added.

## [0.8.7](https://github.com/fivetran/go-fivetran/compare/v0.8.6...v0.8.7)

Expand Down
6 changes: 4 additions & 2 deletions connectors/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ type connectorSchemaConfigModifyRequest struct {
}

type ConnectorColumnConfigListResponse struct {
Code string `json:"code"`
Columns map[string]*ConnectorSchemaConfigColumnResponse `json:"columns"`
common.CommonResponse
Data struct {
Columns map[string]*ConnectorSchemaConfigColumnResponse `json:"columns"`
} `json:"data"`
}

type connectorColumnConfigModifyRequest struct {
Expand Down
176 changes: 89 additions & 87 deletions connectors/connector_column_config_list_test.go
Original file line number Diff line number Diff line change
@@ -1,105 +1,107 @@
package connectors_test

import (
"context"
"fmt"
"net/http"
"testing"
"context"
"fmt"
"net/http"
"testing"

"github.com/fivetran/go-fivetran/connectors"

"github.com/fivetran/go-fivetran/tests/mock"
"github.com/fivetran/go-fivetran/connectors"

testutils "github.com/fivetran/go-fivetran/test_utils"
"github.com/fivetran/go-fivetran/tests/mock"

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

func TestNewConnectorColumnConfigListServiceMock(t *testing.T) {
// arrange
ftClient, mockClient := testutils.CreateTestClient()

handler := mockClient.When(http.MethodGet, fmt.Sprintf("/v1/connectors/%v/schemas/schema_1/tables/table_1/columns", testutils.TEST_CONNECTOR_ID)).ThenCall(
func(req *http.Request) (*http.Response, error) {
response := mock.NewResponse(req, http.StatusOK, prepareConnectorColumnConfigListResponse())
return response, nil
})

svc := ftClient.
NewConnectorColumnConfigListService().
ConnectorId(testutils.TEST_CONNECTOR_ID).
Schema("schema_1").
Table("table_1")

//act
response, err := svc.
Do(context.Background())

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

interactions := mockClient.Interactions()
testutils.AssertEqual(t, len(interactions), 1)
testutils.AssertEqual(t, interactions[0].Handler, handler)
testutils.AssertEqual(t, handler.Interactions, 1)
assertConnectorColumnConfigListResponse(t, response)
// arrange
ftClient, mockClient := testutils.CreateTestClient()

handler := mockClient.When(http.MethodGet, fmt.Sprintf("/v1/connectors/%v/schemas/schema_1/tables/table_1/columns", testutils.TEST_CONNECTOR_ID)).ThenCall(
func(req *http.Request) (*http.Response, error) {
response := mock.NewResponse(req, http.StatusOK, prepareConnectorColumnConfigListResponse())
return response, nil
})

svc := ftClient.
NewConnectorColumnConfigListService().
ConnectorId(testutils.TEST_CONNECTOR_ID).
Schema("schema_1").
Table("table_1")

//act
response, err := svc.
Do(context.Background())

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

interactions := mockClient.Interactions()
testutils.AssertEqual(t, len(interactions), 1)
testutils.AssertEqual(t, interactions[0].Handler, handler)
testutils.AssertEqual(t, handler.Interactions, 1)
assertConnectorColumnConfigListResponse(t, response)
}

func assertConnectorColumnConfigListResponse(t *testing.T, response connectors.ConnectorColumnConfigListResponse) {
testutils.AssertEqual(t, response.Code, "Success")

testutils.AssertEqual(t, len(response.Columns), 3)

column_1 := response.Columns["column_1"]
testutils.AssertEqual(t, *column_1.NameInDestination, "column_1")
testutils.AssertEqual(t, *column_1.Enabled, true)
testutils.AssertEqual(t, *column_1.Hashed, false)
testutils.AssertEqual(t, *column_1.EnabledPatchSettings.Allowed, false)
testutils.AssertEqual(t, *column_1.EnabledPatchSettings.ReasonCode, "SYSTEM_COLUMN")
testutils.AssertEqual(t, *column_1.EnabledPatchSettings.Reason, "The column does not support exclusion as it is a Primary Key")

column_2 := response.Columns["column_2"]
testutils.AssertEqual(t, *column_2.NameInDestination, "column_2")
testutils.AssertEqual(t, *column_2.Enabled, true)
testutils.AssertEqual(t, *column_2.Hashed, false)
testutils.AssertEqual(t, *column_2.EnabledPatchSettings.Allowed, true)

column_3 := response.Columns["column_3"]
testutils.AssertEqual(t, *column_3.NameInDestination, "column_3")
testutils.AssertEqual(t, *column_3.Enabled, false)
testutils.AssertEqual(t, *column_3.Hashed, false)
testutils.AssertEqual(t, *column_3.EnabledPatchSettings.Allowed, true)
testutils.AssertEqual(t, response.Code, "Success")

testutils.AssertEqual(t, len(response.Data.Columns), 3)

column_1 := response.Data.Columns["column_1"]
testutils.AssertEqual(t, *column_1.NameInDestination, "column_1")
testutils.AssertEqual(t, *column_1.Enabled, true)
testutils.AssertEqual(t, *column_1.Hashed, false)
testutils.AssertEqual(t, *column_1.EnabledPatchSettings.Allowed, false)
testutils.AssertEqual(t, *column_1.EnabledPatchSettings.ReasonCode, "SYSTEM_COLUMN")
testutils.AssertEqual(t, *column_1.EnabledPatchSettings.Reason, "The column does not support exclusion as it is a Primary Key")

column_2 := response.Data.Columns["column_2"]
testutils.AssertEqual(t, *column_2.NameInDestination, "column_2")
testutils.AssertEqual(t, *column_2.Enabled, true)
testutils.AssertEqual(t, *column_2.Hashed, false)
testutils.AssertEqual(t, *column_2.EnabledPatchSettings.Allowed, true)

column_3 := response.Data.Columns["column_3"]
testutils.AssertEqual(t, *column_3.NameInDestination, "column_3")
testutils.AssertEqual(t, *column_3.Enabled, false)
testutils.AssertEqual(t, *column_3.Hashed, false)
testutils.AssertEqual(t, *column_3.EnabledPatchSettings.Allowed, true)
}

func prepareConnectorColumnConfigListResponse() string {
return `{
return `{
"code": "Success",
"columns": {
"column_1": {
"name_in_destination": "column_1",
"enabled": true,
"hashed": false,
"enabled_patch_settings": {
"allowed": false,
"reason_code": "SYSTEM_COLUMN",
"reason": "The column does not support exclusion as it is a Primary Key"
}
},
"column_2": {
"name_in_destination": "column_2",
"enabled": true,
"hashed": false,
"enabled_patch_settings": {
"allowed": true
}
},
"column_3": {
"name_in_destination": "column_3",
"enabled": false,
"hashed": false,
"enabled_patch_settings": {
"allowed": true
"data":{
"columns": {
"column_1": {
"name_in_destination": "column_1",
"enabled": true,
"hashed": false,
"enabled_patch_settings": {
"allowed": false,
"reason_code": "SYSTEM_COLUMN",
"reason": "The column does not support exclusion as it is a Primary Key"
}
},
"column_2": {
"name_in_destination": "column_2",
"enabled": true,
"hashed": false,
"enabled_patch_settings": {
"allowed": true
}
},
"column_3": {
"name_in_destination": "column_3",
"enabled": false,
"hashed": false,
"enabled_patch_settings": {
"allowed": true
}
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions connectors/connector_schema_config_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ type ConnectorSchemaConfigTableRequest struct {
}

type ConnectorSchemaConfigTableResponse struct {
NameInDestination *string `json:"name_in_destination"`
Enabled *bool `json:"enabled"`
SyncMode *string `json:"sync_mode"`
Columns map[string]*ConnectorSchemaConfigColumnResponse `json:"columns"`
EnabledPatchSettings struct {
NameInDestination *string `json:"name_in_destination"`
Enabled *bool `json:"enabled"`
SyncMode *string `json:"sync_mode"`
Columns map[string]*ConnectorSchemaConfigColumnResponse `json:"columns"`
SupportsColumnsConfig *bool `json:"supports_columns_config"`
EnabledPatchSettings struct {
Allowed *bool `json:"allowed"`
ReasonCode *string `json:"reason_code"`
Reason *string `json:"reason"`
Expand Down

0 comments on commit bd04085

Please sign in to comment.