Skip to content

Commit

Permalink
Fix registered_at1in proxy agent
Browse files Browse the repository at this point in the history
  • Loading branch information
fivetran-jovanmanojlovic committed Sep 2, 2024
1 parent b6c6c4b commit eb4a0c0
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 180 deletions.
32 changes: 16 additions & 16 deletions fivetran/framework/core/model/proxy_agent.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package model

import (
"github.com/fivetran/go-fivetran/proxy"
"github.com/fivetran/go-fivetran/proxy"
)

type proxyAgentModel interface {
SetId(string)
SetRegistredAt(string)
SetGroupRegion(string)
SetAuthToken(string)
SetSalt(string)
SetCreatedBy(string)
SetDisplayName(string)
SetId(string)
SetRegisteredAt(string)
SetGroupRegion(string)
SetAuthToken(string)
SetSalt(string)
SetCreatedBy(string)
SetDisplayName(string)
}

func readProxyAgentFromResponse(d proxyAgentModel, resp proxy.ProxyDetailsResponse) {
d.SetId(resp.Data.Id)
d.SetRegistredAt(resp.Data.RegistredAt)
d.SetGroupRegion(resp.Data.Region)
d.SetAuthToken(resp.Data.Token)
d.SetSalt(resp.Data.Salt)
d.SetCreatedBy(resp.Data.CreatedBy)
d.SetDisplayName(resp.Data.DisplayName)
}
d.SetId(resp.Data.Id)
d.SetRegisteredAt(resp.Data.RegisteredAt)
d.SetGroupRegion(resp.Data.Region)
d.SetAuthToken(resp.Data.Token)
d.SetSalt(resp.Data.Salt)
d.SetCreatedBy(resp.Data.CreatedBy)
d.SetDisplayName(resp.Data.DisplayName)
}
18 changes: 9 additions & 9 deletions fivetran/framework/core/model/proxy_agent_datasource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import (
)

type ProxyAgentDatasourceModel struct {
Id types.String `tfsdk:"id"`
RegistredAt types.String `tfsdk:"registred_at"`
GroupRegion types.String `tfsdk:"group_region"`
AuthToken types.String `tfsdk:"token"`
Salt types.String `tfsdk:"salt"`
CreatedBy types.String `tfsdk:"created_by"`
DisplayName types.String `tfsdk:"display_name"`
Id types.String `tfsdk:"id"`
RegisteredAt types.String `tfsdk:"registred_at"`
GroupRegion types.String `tfsdk:"group_region"`
AuthToken types.String `tfsdk:"token"`
Salt types.String `tfsdk:"salt"`
CreatedBy types.String `tfsdk:"created_by"`
DisplayName types.String `tfsdk:"display_name"`
}

var _ proxyAgentModel = &ProxyAgentDatasourceModel{}

func (d *ProxyAgentDatasourceModel) SetId(value string) {
d.Id = types.StringValue(value)
}
func (d *ProxyAgentDatasourceModel) SetRegistredAt(value string) {
d.RegistredAt = types.StringValue(value)
func (d *ProxyAgentDatasourceModel) SetRegisteredAt(value string) {
d.RegisteredAt = types.StringValue(value)
}
func (d *ProxyAgentDatasourceModel) SetGroupRegion(value string) {
d.GroupRegion = types.StringValue(value)
Expand Down
26 changes: 13 additions & 13 deletions fivetran/framework/core/model/proxy_agent_resource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import (
)

type ProxyAgentResourceModel struct {
Id types.String `tfsdk:"id"`
RegistredAt types.String `tfsdk:"registred_at"`
GroupRegion types.String `tfsdk:"group_region"`
AuthToken types.String `tfsdk:"token"`
Salt types.String `tfsdk:"salt"`
CreatedBy types.String `tfsdk:"created_by"`
DisplayName types.String `tfsdk:"display_name"`
ProxyServerUri types.String `tfsdk:"proxy_server_uri"`
Id types.String `tfsdk:"id"`
RegisteredAt types.String `tfsdk:"registred_at"`
GroupRegion types.String `tfsdk:"group_region"`
AuthToken types.String `tfsdk:"token"`
Salt types.String `tfsdk:"salt"`
CreatedBy types.String `tfsdk:"created_by"`
DisplayName types.String `tfsdk:"display_name"`
ProxyServerUri types.String `tfsdk:"proxy_server_uri"`
}

var _ proxyAgentModel = &ProxyAgentResourceModel{}

func (d *ProxyAgentResourceModel) SetId(value string) {
d.Id = types.StringValue(value)
}
func (d *ProxyAgentResourceModel) SetRegistredAt(value string) {
d.RegistredAt = types.StringValue(value)
func (d *ProxyAgentResourceModel) SetRegisteredAt(value string) {
d.RegisteredAt = types.StringValue(value)
}
func (d *ProxyAgentResourceModel) SetGroupRegion(value string) {
d.GroupRegion = types.StringValue(value)
Expand All @@ -45,7 +45,7 @@ func (d *ProxyAgentResourceModel) ReadFromResponse(resp proxy.ProxyDetailsRespon
}

func (d *ProxyAgentResourceModel) ReadFromCreateResponse(resp proxy.ProxyCreateResponse) {
d.Id = types.StringValue(resp.Data.AgentId)
d.AuthToken = types.StringValue(resp.Data.AuthToken)
d.ProxyServerUri = types.StringValue(resp.Data.ProxyServerUri)
d.Id = types.StringValue(resp.Data.AgentId)
d.AuthToken = types.StringValue(resp.Data.AuthToken)
d.ProxyServerUri = types.StringValue(resp.Data.ProxyServerUri)
}
71 changes: 35 additions & 36 deletions fivetran/framework/core/model/proxy_agents.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
package model

import (
"context"
"context"

"github.com/fivetran/go-fivetran/proxy"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/fivetran/go-fivetran/proxy"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
)

type ProxyAgents struct {
Items types.Set `tfsdk:"items"`
Items types.Set `tfsdk:"items"`
}

func (d *ProxyAgents) ReadFromResponse(ctx context.Context, resp proxy.ProxyListResponse) {
elementType := map[string]attr.Type{
"id": types.StringType,
"registred_at": types.StringType,
"group_region": types.StringType,
"token": types.StringType,
"salt": types.StringType,
"created_by": types.StringType,
"display_name": types.StringType,
}

if resp.Data.Items == nil {
d.Items = types.SetNull(types.ObjectType{AttrTypes: elementType})
}

items := []attr.Value{}
for _, v := range resp.Data.Items {
item := map[string]attr.Value{}
item["id"] = types.StringValue(v.Id)
item["registred_at"] = types.StringValue(v.RegistredAt)
item["group_region"] = types.StringValue(v.Region)
item["token"] = types.StringValue(v.Token)
item["salt"] = types.StringValue(v.Salt)
item["created_by"] = types.StringValue(v.CreatedBy)
item["display_name"] = types.StringValue(v.DisplayName)
objectValue, _ := types.ObjectValue(elementType, item)
items = append(items, objectValue)
}

d.Items, _ = types.SetValue(types.ObjectType{AttrTypes: elementType}, items)
elementType := map[string]attr.Type{
"id": types.StringType,
"registred_at": types.StringType,
"group_region": types.StringType,
"token": types.StringType,
"salt": types.StringType,
"created_by": types.StringType,
"display_name": types.StringType,
}

if resp.Data.Items == nil {
d.Items = types.SetNull(types.ObjectType{AttrTypes: elementType})
}

items := []attr.Value{}

for _, v := range resp.Data.Items {
item := map[string]attr.Value{}
item["id"] = types.StringValue(v.Id)
item["registred_at"] = types.StringValue(v.RegisteredAt)
item["group_region"] = types.StringValue(v.Region)
item["token"] = types.StringValue(v.Token)
item["salt"] = types.StringValue(v.Salt)
item["created_by"] = types.StringValue(v.CreatedBy)
item["display_name"] = types.StringValue(v.DisplayName)
objectValue, _ := types.ObjectValue(elementType, item)
items = append(items, objectValue)
}

d.Items, _ = types.SetValue(types.ObjectType{AttrTypes: elementType}, items)
}

98 changes: 49 additions & 49 deletions fivetran/framework/datasources/proxy_agent_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package datasources_test

import (
"net/http"
"testing"
"net/http"
"testing"

"github.com/fivetran/go-fivetran/tests/mock"
tfmock "github.com/fivetran/terraform-provider-fivetran/fivetran/tests/mock"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/fivetran/go-fivetran/tests/mock"
tfmock "github.com/fivetran/terraform-provider-fivetran/fivetran/tests/mock"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const (
proxyAgentMappingResponse = `
proxyAgentMappingResponse = `
{
"id": "id",
"account_id": "account_id",
"registred_at": "registred_at",
"registered_at": "registered_at",
"region": "region",
"token": "token",
"salt": "salt",
Expand All @@ -26,59 +26,59 @@ const (
)

var (
proxyAgentDataSourceMockGetHandler *mock.Handler
proxyAgentDataSourceMockGetHandler *mock.Handler

proxyAgentDataSourceMockData map[string]interface{}
proxyAgentDataSourceMockData map[string]interface{}
)

func setupMockClientProxyAgentDataSourceConfigMapping(t *testing.T) {
tfmock.MockClient().Reset()
tfmock.MockClient().Reset()

proxyAgentDataSourceMockGetHandler = tfmock.MockClient().When(http.MethodGet, "/v1/proxy/id").ThenCall(
func(req *http.Request) (*http.Response, error) {
proxyAgentDataSourceMockData = tfmock.CreateMapFromJsonString(t, proxyAgentMappingResponse)
return tfmock.FivetranSuccessResponse(t, req, http.StatusOK, "Success", proxyAgentDataSourceMockData), nil
},
)
proxyAgentDataSourceMockGetHandler = tfmock.MockClient().When(http.MethodGet, "/v1/proxy/id").ThenCall(
func(req *http.Request) (*http.Response, error) {
proxyAgentDataSourceMockData = tfmock.CreateMapFromJsonString(t, proxyAgentMappingResponse)
return tfmock.FivetranSuccessResponse(t, req, http.StatusOK, "Success", proxyAgentDataSourceMockData), nil
},
)
}

func TestDataSourceProxyAgentConfigMappingMock(t *testing.T) {
step1 := resource.TestStep{
Config: `
step1 := resource.TestStep{
Config: `
data "fivetran_proxy_agent" "test_proxy_agent" {
provider = fivetran-provider
id = "id"
}`,

Check: resource.ComposeAggregateTestCheckFunc(
func(s *terraform.State) error {
tfmock.AssertEqual(t, proxyAgentDataSourceMockGetHandler.Interactions, 1)
tfmock.AssertNotEmpty(t, proxyAgentDataSourceMockData)
return nil
},
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "id", "id"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "registred_at", "registred_at"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "group_region", "region"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "token", "token"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "salt", "salt"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "created_by", "created_by"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "display_name", "display_name"),
),
}
Check: resource.ComposeAggregateTestCheckFunc(
func(s *terraform.State) error {
tfmock.AssertEqual(t, proxyAgentDataSourceMockGetHandler.Interactions, 1)
tfmock.AssertNotEmpty(t, proxyAgentDataSourceMockData)
return nil
},
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "id", "id"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "registred_at", "registered_at"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "group_region", "region"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "token", "token"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "salt", "salt"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "created_by", "created_by"),
resource.TestCheckResourceAttr("data.fivetran_proxy_agent.test_proxy_agent", "display_name", "display_name"),
),
}

resource.Test(
t,
resource.TestCase{
PreCheck: func() {
setupMockClientProxyAgentDataSourceConfigMapping(t)
},
ProtoV6ProviderFactories: tfmock.ProtoV6ProviderFactories,
CheckDestroy: func(s *terraform.State) error {
return nil
},
Steps: []resource.TestStep{
step1,
},
},
)
resource.Test(
t,
resource.TestCase{
PreCheck: func() {
setupMockClientProxyAgentDataSourceConfigMapping(t)
},
ProtoV6ProviderFactories: tfmock.ProtoV6ProviderFactories,
CheckDestroy: func(s *terraform.State) error {
return nil
},
Steps: []resource.TestStep{
step1,
},
},
)
}
Loading

0 comments on commit eb4a0c0

Please sign in to comment.