diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ad113f..89ffbe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,20 @@ 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.3...HEAD) +## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v0.8.4...HEAD) + +## [0.8.4](https://github.com/fivetran/go-fivetran/compare/v0.8.3...v0.8.4) + +## Added + +Supported the following Fivetran API endpoints for Proxy Agents Management: +- [Create a Proxy Agent](/docs/rest-api/proxy-management#createaproxyagent) +- [List all Proxy Agents](/docs/rest-api/proxy-management#listallproxyagents) +- [Retrieve Proxy Agent Details](/docs/rest-api/proxy-management#retrieveproxyagentdetails) +- [Delete a Proxy Agent](/docs/rest-api/proxy-management#deleteaproxyagent) +- [Return all connections attached to the proxy agent](/docs/rest-api/proxy-management#returnsallconnectionsattachedtotheproxyagent) +- [Attach connection to the proxy agent](/docs/rest-api/proxy-management#attachconnectiontotheproxyagent) +- [Detach connection from the proxy agent](/docs/rest-api/proxy-management#detachconnectionformtheproxyagent) ## [0.8.3](https://github.com/fivetran/go-fivetran/compare/v0.8.2...v0.8.3) diff --git a/README.md b/README.md index 3f6e1b5..e77c99f 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,16 @@ REST API Endpoint | REST API Version | SDK Service [Invite a user](https://fivetran.com/docs/rest-api/users#inviteauser) | v1 | [UserInviteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserInviteService) [Modify a user](https://fivetran.com/docs/rest-api/users#modifyauser) | v1 | [UserModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserModifyService) [Delete a user](https://fivetran.com/docs/rest-api/users#deleteauser) | v1 | [UserDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserDeleteService) +[List all connector memberships](https://fivetran.com/docs/rest-api/users#listallconnectormemberships) | v1 | [UserConnectorMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserConnectorMembershipsListService) +[Retrieve connector membership](https://fivetran.com/docs/rest-api/users#retrieveconnectormembership) | v1 | [UserConnectorMembershipDetailsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserConnectorMembershipDetailsService) +[Add connector membership](https://fivetran.com/docs/rest-api/users#addconnectormembership) | v1 | [UserConnectorMembershipCreateService](https://pkg.go.dev/github.com/fivetran/go-UserConnectorMembershipCreateService#UserDeleteService) +[Update connector membership](https://fivetran.com/docs/rest-api/users#updateconnectormembership) | v1 | [UserConnectorMembershipModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserConnectorMembershipModifyService) +[Delete connector membership](https://fivetran.com/docs/rest-api/users#deleteconnectormembership) | v1 | [UserConnectorMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserConnectorMembershipDeleteService) +[List all group memberships](https://fivetran.com/docs/rest-api/users#listallgroupmemberships) | v1 | [UserGroupMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipsListService) +[Retrieve group membership](https://fivetran.com/docs/rest-api/users#retrievegroupmembership) | v1 | [UserGroupMembershipDetailsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipDetailsService) +[Add group membership](https://fivetran.com/docs/rest-api/users#addgroupmembership) | v1 | [UserGroupMembershipCreateService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipCreateService) +[Update group membership](https://fivetran.com/docs/rest-api/users#updategroupmembership) | v1 | [UserGroupMembershipModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipModifyService) +[Delete group membership](https://fivetran.com/docs/rest-api/users#deletegroupmembership) | v1 | [UserGroupMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipDeleteService) ### [Group Management API](https://fivetran.com/docs/rest-api/groups) @@ -214,6 +224,7 @@ REST API Endpoint | REST API Version | SDK Service/Config [Delete a team](https://fivetran.com/docs/rest-api/teams#deleteateam) | v1 | [TeamsDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamsDeleteService) ### [Team Management User memberships](https://fivetran.com/docs/rest-api/teams#usermemberships) + REST API Endpoint | REST API Version | SDK Service/Config --- | --- | --- [List all user memberships](https://fivetran.com/docs/rest-api/teams#listallusermemberships) | v1 | [TeamUserMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamUserMembershipsListService) @@ -223,6 +234,7 @@ REST API Endpoint | REST API Version | SDK Service/Config [Delete a user from a team](https://fivetran.com/docs/rest-api/teams#deleteauserfromateam) | v1 | [TeamUserMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamUserMembershipDeleteService) ### [Team Management Connector memberships](https://fivetran.com/docs/rest-api/teams#connectormemberships) + REST API Endpoint | REST API Version | SDK Service/Config --- | --- | --- [List all connector memberships](https://fivetran.com/docs/rest-api/teams#listallconnectormemberships) | v1 | [TeamConnectorMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamConnectorMembershipsListService) @@ -232,6 +244,7 @@ REST API Endpoint | REST API Version | SDK Service/Config [Delete connector membership](https://fivetran.com/docs/rest-api/teams#deleteconnectormembership) | v1 | [TeamConnectorMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamConnectorMembershipDeleteService) ### [Team Management Group memberships](https://fivetran.com/docs/rest-api/teams#groupmemberships) + REST API Endpoint | REST API Version | SDK Service/Config --- | --- | --- [List all group memberships](https://fivetran.com/docs/rest-api/teams#listallgroupmemberships) | v1 | [TeamGroupMembershipsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamGroupMembershipsService) @@ -240,6 +253,28 @@ REST API Endpoint | REST API Version | SDK Service/Config [Update group membership](https://fivetran.com/docs/rest-api/teams#updategroupmembership) | v1 | [TeamGroupMembershipModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamGroupMembershipModifyService) [Delete group membership](https://fivetran.com/docs/rest-api/teams#deletegroupmembership) | v1 | [TeamGroupMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamGroupMembershipDeleteService) +### [Private Links Management](https://fivetran.com/docs/rest-api/private-links-management) + +REST API Endpoint | REST API Version | SDK Service/Config +--- | --- | --- +[Create a Private Link](https://fivetran.com/docs/rest-api/private-links-management#createaprivatelink) | v1 | [PrivateLinksCreateService](https://pkg.go.dev/github.com/fivetran/go-fivetran#PrivateLinksCreateService) +[List all Private Links within Group](https://fivetran.com/docs/rest-api/private-links-management#listallprivatelinkswithingroup) | v1 | [GroupListPrivateLinksService](https://pkg.go.dev/github.com/fivetran/go-fivetran#GroupListPrivateLinksService) +[Retrieve Private Link Details](https://fivetran.com/docs/rest-api/private-links-management#retrieveprivatelinkdetails) | v1 | [PrivateLinksDetailsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#PrivateLinksDetailsService) +[Update a Private Link](https://fivetran.com/docs/rest-api/private-links-management#updateaprivatelink) | v1 | [PrivateLinksModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#PrivateLinksModifyService) +[Delete a Private Link](https://fivetran.com/docs/rest-api/private-links-management#deleteaprivatelink) | v1 | [PrivateLinksDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#PrivateLinksDeleteService) + +### [Proxy Agents Management](https://fivetran.com/docs/rest-api/proxy-management) + +REST API Endpoint | REST API Version | SDK Service/Config +--- | --- | --- +[Create a Proxy Agent](/docs/rest-api/proxy-management#createaproxyagent) | v1 | [ProxyCreateService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyCreateService) +[List all Proxy Agents](/docs/rest-api/proxy-management#listallproxyagents) | v1 | [ProxyListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyListService) +[Retrieve Proxy Agent Details](/docs/rest-api/proxy-management#retrieveproxyagentdetails) | v1 | [ProxyDetailsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyDetailsService) +[Delete a Proxy Agent](/docs/rest-api/proxy-management#deleteaproxyagent) | v1 | [ProxyDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyDeleteService) +[Return all connections attached to the proxy agent](/docs/rest-api/proxy-management#returnsallconnectionsattachedtotheproxyagent) | v1 | [ProxyConnectionMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyConnectionMembershipsListService) +[Attach connection to the proxy agent](/docs/rest-api/proxy-management#attachconnectiontotheproxyagent) | v1 | [ProxyConnectionMembershipCreateService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyConnectionMembershipCreateService) +[Detach connection from the proxy agent](/docs/rest-api/proxy-management#detachconnectionformtheproxyagent) | v1 | [ProxyConnectionMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyConnectionMembershipDeleteService) + ## Support Please get in touch with us through our [Support Portal](https://support.fivetran.com/) if you diff --git a/client.go b/client.go index 752a23c..c9b0e73 100644 --- a/client.go +++ b/client.go @@ -19,6 +19,7 @@ import ( "github.com/fivetran/go-fivetran/teams" "github.com/fivetran/go-fivetran/users" "github.com/fivetran/go-fivetran/webhooks" + "github.com/fivetran/go-fivetran/proxy" ) // Client holds client configuration @@ -35,7 +36,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/0.8.2" +const defaultUserAgent = "Go-Fivetran/0.8.4" // New receives API Key and API Secret, and returns a new Client with the // default HTTP client @@ -601,3 +602,32 @@ func (c *Client) NewPrivateLinksDetails() *privatelinks.PrivateLinksDetailsServi func (c *Client) NewPrivateLinksModify() *privatelinks.PrivateLinksModifyService { return &privatelinks.PrivateLinksModifyService{HttpService: c.NewHttpService()} } + +/* Proxy */ +func (c *Client) NewProxyCreate() *proxy.ProxyCreateService { + return &proxy.ProxyCreateService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewProxyList() *proxy.ProxyListService { + return &proxy.ProxyListService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewProxyDetails() *proxy.ProxyDetailsService { + return &proxy.ProxyDetailsService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewProxyDelete() *proxy.ProxyDeleteService { + return &proxy.ProxyDeleteService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewProxyConnectionMembershipCreate() *proxy.ProxyConnectionMembershipCreateService { + return &proxy.ProxyConnectionMembershipCreateService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewProxyConnectionMembershipsList() *proxy.ProxyConnectionMembershipsListService { + return &proxy.ProxyConnectionMembershipsListService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewProxyConnectionMembershipDelete() *proxy.ProxyConnectionMembershipDeleteService { + return &proxy.ProxyConnectionMembershipDeleteService{HttpService: c.NewHttpService()} +} \ No newline at end of file diff --git a/private_links/private_links_create.go b/private_links/private_links_create.go index f0ab007..96206b7 100644 --- a/private_links/private_links_create.go +++ b/private_links/private_links_create.go @@ -2,7 +2,6 @@ package privatelinks import ( "context" - "fmt" httputils "github.com/fivetran/go-fivetran/http_utils" ) @@ -47,7 +46,6 @@ func (s *PrivateLinksCreateService) Config(value *PrivateLinksConfig) *PrivateLi func (s *PrivateLinksCreateService) Do(ctx context.Context) (PrivateLinksResponse, error) { var response PrivateLinksResponse - fmt.Printf("request %v", s.request()) err := s.HttpService.Do(ctx, "POST", "/private-links", s.request(), nil, 201, &response) return response, err } \ No newline at end of file diff --git a/proxy/common_types.go b/proxy/common_types.go new file mode 100644 index 0000000..a99e5ef --- /dev/null +++ b/proxy/common_types.go @@ -0,0 +1,61 @@ +package proxy + +import ( + "github.com/fivetran/go-fivetran/common" +) + +type ProxyCreateData struct { + AgentId string `json:"agent_id"` + AuthToken string `json:"auth_token"` + ProxyServerUri string `json:"proxy_server_uri"` +} + +type ProxyData struct { + Id string `json:"id"` + AccountId string `json:"account_id"` + RegistredAt string `json:"registred_at"` + Region string `json:"region"` + Token string `json:"token"` + Salt string `json:"salt"` + CreatedBy string `json:"created_by"` + DisplayName string `json:"display_name"` +} + +type proxyCreateRequest struct { + DisplayName *string `json:"display_name,omitempty"` + GroupId *string `json:"group_id,omitempty"` +} + +type ProxyCreateResponse struct { + common.CommonResponse + Data ProxyCreateData `json:"data"` +} + +type ProxyListResponse struct { + Code string `json:"code"` + Data struct { + Items []ProxyData `json:"items"` + NextCursor string `json:"next_cursor"` + } `json:"data"` +} + +type ProxyDetailsResponse struct { + Code string `json:"code"` + Data ProxyData `json:"data"` +} + +type ProxyConnectionMembershipsListResponse struct { + Code string `json:"code"` + Data struct { + Items []ProxyConnectionMembership `json:"items"` + NextCursor string `json:"next_cursor"` + } `json:"data"` +} + +type ProxyConnectionMembership struct { + ConnectionId string `json:"connection_id"` +} + +type proxyConnectionMembershipCreateRequest struct { + ConnectionId *string `json:"connection_id,omitempty"` +} \ No newline at end of file diff --git a/proxy/proxy_connection_membership_create.go b/proxy/proxy_connection_membership_create.go new file mode 100644 index 0000000..99deda4 --- /dev/null +++ b/proxy/proxy_connection_membership_create.go @@ -0,0 +1,45 @@ +package proxy + +import ( + "context" + "fmt" + "github.com/fivetran/go-fivetran/common" + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// ProxyConnectionMembershipCreateService implements the Proxy Agent Management, Attach connection to the proxy agent +// Ref. https://fivetran.com/docs/rest-api/proxy-management#attachconnectiontotheproxyagent +type ProxyConnectionMembershipCreateService struct { + httputils.HttpService + proxyId *string + connectionId *string +} + +func (s *ProxyConnectionMembershipCreateService) request() *proxyConnectionMembershipCreateRequest { + return &proxyConnectionMembershipCreateRequest{ + ConnectionId: s.connectionId, + } +} + +func (s *ProxyConnectionMembershipCreateService) ProxyId(value string) *ProxyConnectionMembershipCreateService { + s.proxyId = &value + return s +} + +func (s *ProxyConnectionMembershipCreateService) ConnectionId(value string) *ProxyConnectionMembershipCreateService { + s.connectionId = &value + return s +} + +func (s *ProxyConnectionMembershipCreateService) Do(ctx context.Context) (common.CommonResponse, error) { + var response common.CommonResponse + if s.proxyId == nil { + return response, fmt.Errorf("missing required proxyId") + } + if s.connectionId == nil { + return response, fmt.Errorf("missing required connectionId") + } + url := fmt.Sprintf("/proxy/%v/connections", *s.proxyId) + err := s.HttpService.Do(ctx, "POST", url, s.request(), nil, 201, &response) + return response, err +} diff --git a/proxy/proxy_connection_membership_create_test.go b/proxy/proxy_connection_membership_create_test.go new file mode 100644 index 0000000..32dbccc --- /dev/null +++ b/proxy/proxy_connection_membership_create_test.go @@ -0,0 +1,61 @@ +package proxy_test + +import ( + "context" + "fmt" + "net/http" + "testing" + + "github.com/fivetran/go-fivetran/common" + "github.com/fivetran/go-fivetran/tests/mock" + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestNewProxyConnectionCreate(t *testing.T) { + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/proxy/proxy_id/connections").ThenCall( + + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertProxyConnectionCreateRequest(t, body) + response := mock.NewResponse(req, http.StatusCreated, prepareProxyConnectionCreateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewProxyConnectionMembershipCreate(). + ProxyId("proxy_id"). + ConnectionId("connection_id"). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertProxyConnectionCreateResponse(t, response) +} + +func prepareProxyConnectionCreateResponse() string { + return fmt.Sprintf( + `{ + "code": "Success", + "message": "string" + }`) +} + +func assertProxyConnectionCreateRequest(t *testing.T, request map[string]interface{}) { + testutils.AssertKey(t, "connection_id", request, "connection_id") +} + +func assertProxyConnectionCreateResponse(t *testing.T, response common.CommonResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertNotEmpty(t, response.Message) +} diff --git a/proxy/proxy_connection_membership_delete.go b/proxy/proxy_connection_membership_delete.go new file mode 100644 index 0000000..6f3b954 --- /dev/null +++ b/proxy/proxy_connection_membership_delete.go @@ -0,0 +1,43 @@ +package proxy + +import ( + "context" + "fmt" + + "github.com/fivetran/go-fivetran/common" + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// ProxyConnectionMembershipDeleteService implements the Proxy Agent Management, Detach connection from the proxy agent +// Ref. https://fivetran.com/docs/rest-api/proxy-management#detachconnectionfromtheproxyagent +type ProxyConnectionMembershipDeleteService struct { + httputils.HttpService + proxyId *string + connectionId *string +} + +func (s *ProxyConnectionMembershipDeleteService) ProxyId(value string) *ProxyConnectionMembershipDeleteService { + s.proxyId = &value + return s +} + +func (s *ProxyConnectionMembershipDeleteService) ConnectionId(value string) *ProxyConnectionMembershipDeleteService { + s.connectionId = &value + return s +} + +func (s *ProxyConnectionMembershipDeleteService) Do(ctx context.Context) (common.CommonResponse, error) { + var response common.CommonResponse + + if s.proxyId == nil { + return response, fmt.Errorf("missing required proxyId") + } + + if s.connectionId == nil { + return response, fmt.Errorf("missing required connectionId") + } + + url := fmt.Sprintf("/proxy/%v/connections/%v", *s.proxyId, *s.connectionId) + err := s.HttpService.Do(ctx, "DELETE", url, nil, nil, 200, &response) + return response, err +} \ No newline at end of file diff --git a/proxy/proxy_connection_membership_delete_test.go b/proxy/proxy_connection_membership_delete_test.go new file mode 100644 index 0000000..b22045b --- /dev/null +++ b/proxy/proxy_connection_membership_delete_test.go @@ -0,0 +1,71 @@ +package proxy_test + +import ( + "context" + "fmt" + "net/http" + "testing" + + "github.com/fivetran/go-fivetran/common" + + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestProxyConnectionDeleteServiceDo(t *testing.T) { + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodDelete, "/v1/proxy/proxy_id/connections/connection_id").ThenCall( + func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, `{"code": "Success"}`) + return response, nil + }, + ) + + service := ftClient.NewProxyConnectionMembershipDelete().ProxyId("proxy_id").ConnectionId("connection_id") + + // act + response, err := service.Do(context.Background()) + + // assert + if err != nil { + t.Error(err) + } + + assertProxyConnectionDeleteResponse(t, response, "Success") + + // Check that the expected interactions with the mock client occurred + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) +} + +func TestProxyConnectionDeleteServiceDoMissingId(t *testing.T) { + ftClient, _ := testutils.CreateTestClient() + service := ftClient.NewProxyConnectionMembershipDelete() + + // Call the Do method to execute the request + _, err := service.Do(context.Background()) + + // Check for expected error + expectedError := fmt.Errorf("missing required proxyId") + testutils.AssertEqual(t, err, expectedError) +} + +func TestProxyConnectionDeleteServiceDoMissingConnectionId(t *testing.T) { + ftClient, _ := testutils.CreateTestClient() + service := ftClient.NewProxyConnectionMembershipDelete().ProxyId("proxy_id") + + // Call the Do method to execute the request + _, err := service.Do(context.Background()) + + // Check for expected error + expectedError := fmt.Errorf("missing required connectionId") + testutils.AssertEqual(t, err, expectedError) +} + +func assertProxyConnectionDeleteResponse(t *testing.T, response common.CommonResponse, code string) { + testutils.AssertEqual(t, response.Code, code) +} diff --git a/proxy/proxy_connection_membership_list.go b/proxy/proxy_connection_membership_list.go new file mode 100644 index 0000000..9105ba5 --- /dev/null +++ b/proxy/proxy_connection_membership_list.go @@ -0,0 +1,54 @@ +package proxy + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// ProxyConnectionMembershipsListService implements the Proxy Agent Management, Return all connections attached to the proxy agent +// Ref. https://fivetran.com/docs/rest-api/proxy-management#returnallconnectionsattachedtotheproxyagent +type ProxyConnectionMembershipsListService struct { + httputils.HttpService + proxyId *string + limit *int + cursor *string +} + +func (s *ProxyConnectionMembershipsListService) ProxyId(value string) *ProxyConnectionMembershipsListService { + s.proxyId = &value + return s +} + +func (s *ProxyConnectionMembershipsListService) Limit(value int) *ProxyConnectionMembershipsListService { + s.limit = &value + return s +} + +func (s *ProxyConnectionMembershipsListService) Cursor(value string) *ProxyConnectionMembershipsListService { + s.cursor = &value + return s +} + +func (s *ProxyConnectionMembershipsListService) Do(ctx context.Context) (ProxyConnectionMembershipsListResponse, error) { + var response ProxyConnectionMembershipsListResponse + + if s.proxyId == nil { + return response, fmt.Errorf("missing required proxyId") + } + + url := fmt.Sprintf("/proxy/%v/connections", *s.proxyId) + var queries map[string]string = nil + if s.cursor != nil || s.limit != nil { + queries = make(map[string]string) + if s.cursor != nil { + queries["cursor"] = *s.cursor + } + if s.limit != nil { + queries["limit"] = fmt.Sprintf("%v", *s.limit) + } + } + err := s.HttpService.Do(ctx, "GET", url, nil, queries, 200, &response) + return response, err +} \ No newline at end of file diff --git a/proxy/proxy_connection_membership_list_test.go b/proxy/proxy_connection_membership_list_test.go new file mode 100644 index 0000000..951d8cc --- /dev/null +++ b/proxy/proxy_connection_membership_list_test.go @@ -0,0 +1,60 @@ +package proxy_test + +import ( + "context" + "fmt" + "net/http" + "testing" + + "github.com/fivetran/go-fivetran/proxy" + + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestProxyConnectorListServiceDo(t *testing.T) { + // arrange + + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/proxy/proxy_id/connections"). + ThenCall(func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, prepareProxyConnectorListResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewProxyConnectionMembershipsList(). + ProxyId("proxy_id"). + Do(context.Background()) + + // assert + if err != nil { + 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) + assertProxyConnectionListResponse(t, response) +} + +func prepareProxyConnectorListResponse() string { + return fmt.Sprintf(`{ + "code": "Success", + "data": { + "items": [ + { + "connection_id": "string" + } + ], + "next_cursor": null + } + }`) +} + +func assertProxyConnectionListResponse(t *testing.T, response proxy.ProxyConnectionMembershipsListResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Data.Items[0].ConnectionId, "string") +} \ No newline at end of file diff --git a/proxy/proxy_create.go b/proxy/proxy_create.go new file mode 100644 index 0000000..dfa0be2 --- /dev/null +++ b/proxy/proxy_create.go @@ -0,0 +1,38 @@ +package proxy + +import ( + "context" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// ProxyCreateService implements the Proxy Agent Management, Create a Proxy Agent. +// Ref. https://fivetran.com/docs/rest-api/proxy-management#createaproxyagent +type ProxyCreateService struct { + httputils.HttpService + display_name *string + group_id *string +} + +func (s *ProxyCreateService) request() *proxyCreateRequest { + return &proxyCreateRequest{ + DisplayName: s.display_name, + GroupId: s.group_id, + } +} + +func (s *ProxyCreateService) DisplayName(value string) *ProxyCreateService { + s.display_name = &value + return s +} + +func (s *ProxyCreateService) GroupId(value string) *ProxyCreateService { + s.group_id = &value + return s +} + +func (s *ProxyCreateService) Do(ctx context.Context) (ProxyCreateResponse, error) { + var response ProxyCreateResponse + err := s.HttpService.Do(ctx, "POST", "/proxy", s.request(), nil, 201, &response) + return response, err +} \ No newline at end of file diff --git a/proxy/proxy_create_test.go b/proxy/proxy_create_test.go new file mode 100644 index 0000000..5e916cb --- /dev/null +++ b/proxy/proxy_create_test.go @@ -0,0 +1,72 @@ +package proxy_test + +import ( + "context" + "net/http" + "testing" + + "github.com/fivetran/go-fivetran/proxy" + "github.com/fivetran/go-fivetran/tests/mock" + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +const ( + PROXY_NAME = "Test Proxy" + PROXY_GROUP = "group_id" +) + +func TestNewProxyCreate(t *testing.T) { + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/proxy").ThenCall( + + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertProxyCreateRequest(t, body) + response := mock.NewResponse(req, http.StatusCreated, prepareProxyCreateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewProxyCreate(). + DisplayName(PROXY_NAME). + GroupId(PROXY_GROUP). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertProxyCreateResponse(t, response) +} + +func prepareProxyCreateResponse() string { + return `{ + "code": "Success", + "data": { + "agent_id": "id", + "auth_token": "auth_token", + "proxy_server_uri": "proxy_server_uri" + } + }` +} + +func assertProxyCreateRequest(t *testing.T, request map[string]interface{}) { + testutils.AssertKey(t, "display_name", request, PROXY_NAME) + testutils.AssertKey(t, "group_id", request, PROXY_GROUP) +} + +func assertProxyCreateResponse(t *testing.T, response proxy.ProxyCreateResponse) { + testutils.AssertEqual(t, response.Code, "Success") + + testutils.AssertEqual(t, response.Data.AgentId, "id") + testutils.AssertEqual(t, response.Data.AuthToken, "auth_token") + testutils.AssertEqual(t, response.Data.ProxyServerUri, "proxy_server_uri") +} diff --git a/proxy/proxy_delete.go b/proxy/proxy_delete.go new file mode 100644 index 0000000..77e796a --- /dev/null +++ b/proxy/proxy_delete.go @@ -0,0 +1,33 @@ +package proxy + +import ( + "context" + "fmt" + + "github.com/fivetran/go-fivetran/common" + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// ProxyDeleteService implements the Proxy Agent Management, Delete a Proxy Agent. +// Ref. https://fivetran.com/docs/rest-api/proxy-management#deleteaproxyagent +type ProxyDeleteService struct { + httputils.HttpService + proxyId *string +} + +func (s *ProxyDeleteService) ProxyId(value string) *ProxyDeleteService { + s.proxyId = &value + return s +} + +func (s *ProxyDeleteService) Do(ctx context.Context) (common.CommonResponse, error) { + var response common.CommonResponse + + if s.proxyId == nil { + return response, fmt.Errorf("missing required proxyId") + } + + url := fmt.Sprintf("/proxy/%v", *s.proxyId) + err := s.HttpService.Do(ctx, "DELETE", url, nil, nil, 200, &response) + return response, err +} \ No newline at end of file diff --git a/proxy/proxy_delete_test.go b/proxy/proxy_delete_test.go new file mode 100644 index 0000000..d99502d --- /dev/null +++ b/proxy/proxy_delete_test.go @@ -0,0 +1,62 @@ +package proxy_test + +import ( + "context" + "fmt" + "net/http" + "testing" + + "github.com/fivetran/go-fivetran/common" + + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestProxyDeleteServiceDo(t *testing.T) { + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodDelete, "/v1/proxy/proxy_id").ThenCall( + func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, `{"code": "Success"}`) + return response, nil + }, + ) + + service := ftClient.NewProxyDelete().ProxyId("proxy_id") + + // act + response, err := service.Do(context.Background()) + + // assert + if err != nil { + t.Error(err) + } + + assertProxyDeleteResponse(t, response, "Success") + + // Check that the expected interactions with the mock client occurred + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) +} + +func TestProxyDeleteServiceDoMissingId(t *testing.T) { + // Create a test client + ftClient, _ := testutils.CreateTestClient() + + // Create the ProxyDeleteService without setting the Proxy ID + service := ftClient.NewProxyDelete() + + // Call the Do method to execute the request + _, err := service.Do(context.Background()) + + // Check for expected error + expectedError := fmt.Errorf("missing required proxyId") + testutils.AssertEqual(t, err, expectedError) +} + +func assertProxyDeleteResponse(t *testing.T, response common.CommonResponse, code string) { + testutils.AssertEqual(t, response.Code, code) +} diff --git a/proxy/proxy_details.go b/proxy/proxy_details.go new file mode 100644 index 0000000..9ef2ffe --- /dev/null +++ b/proxy/proxy_details.go @@ -0,0 +1,32 @@ +package proxy + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// ProxyDetailsService implements the Proxy Agent Management, Retrieve Proxy Agent Details. +// Ref. https://fivetran.com/docs/rest-api/proxy-management#retrieveproxyagentdetails +type ProxyDetailsService struct { + httputils.HttpService + proxyId *string +} + +func (s *ProxyDetailsService) ProxyId(value string) *ProxyDetailsService { + s.proxyId = &value + return s +} + +func (s *ProxyDetailsService) Do(ctx context.Context) (ProxyDetailsResponse, error) { + var response ProxyDetailsResponse + + if s.proxyId == nil { + return response, fmt.Errorf("missing required proxyId") + } + + url := fmt.Sprintf("/proxy/%v", *s.proxyId) + err := s.HttpService.Do(ctx, "GET", url, nil, nil, 200, &response) + return response, err +} \ No newline at end of file diff --git a/proxy/proxy_details_test.go b/proxy/proxy_details_test.go new file mode 100644 index 0000000..3a824a7 --- /dev/null +++ b/proxy/proxy_details_test.go @@ -0,0 +1,69 @@ +package proxy_test + +import ( + "context" + "fmt" + "net/http" + "testing" + + "github.com/fivetran/go-fivetran/proxy" + + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestProxyDetailsServiceDo(t *testing.T) { + // arrange + + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/proxy/proxy_id"). + ThenCall(func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, prepareProxyDetailsResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewProxyDetails(). + ProxyId("proxy_id"). + Do(context.Background()) + + // assert + if err != nil { + 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) + assertProxyDetailsResponse(t, response) +} + +func prepareProxyDetailsResponse() string { + return fmt.Sprintf(`{ + "code": "Success", + "data": { + "id": "id", + "account_id": "account_id", + "registred_at": "registred_at", + "region": "region", + "token": "token", + "salt": "salt", + "created_by": "created_by", + "display_name": "display_name" + } + }`) +} + +func assertProxyDetailsResponse(t *testing.T, response proxy.ProxyDetailsResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Data.Id, "id") + testutils.AssertEqual(t, response.Data.AccountId, "account_id") + testutils.AssertEqual(t, response.Data.RegistredAt, "registred_at") + testutils.AssertEqual(t, response.Data.Region, "region") + testutils.AssertEqual(t, response.Data.Token, "token") + testutils.AssertEqual(t, response.Data.Salt, "salt") + testutils.AssertEqual(t, response.Data.CreatedBy, "created_by") + testutils.AssertEqual(t, response.Data.DisplayName, "display_name") +} \ No newline at end of file diff --git a/proxy/proxy_list.go b/proxy/proxy_list.go new file mode 100644 index 0000000..7f28708 --- /dev/null +++ b/proxy/proxy_list.go @@ -0,0 +1,43 @@ +package proxy + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// ProxyListService implements the Proxy Agent Management, retrieve List all Proxy Agents. +// Ref. https://fivetran.com/docs/rest-api/proxy-management#listallproxyagents +type ProxyListService struct { + httputils.HttpService + limit *int + cursor *string +} + +func (s *ProxyListService) Limit(value int) *ProxyListService { + s.limit = &value + return s +} + +func (s *ProxyListService) Cursor(value string) *ProxyListService { + s.cursor = &value + return s +} + +func (s *ProxyListService) Do(ctx context.Context) (ProxyListResponse, error) { + var response ProxyListResponse + + var queries map[string]string = nil + if s.cursor != nil || s.limit != nil { + queries = make(map[string]string) + if s.cursor != nil { + queries["cursor"] = *s.cursor + } + if s.limit != nil { + queries["limit"] = fmt.Sprintf("%v", *s.limit) + } + } + err := s.HttpService.Do(ctx, "GET", "/proxy", nil, queries, 200, &response) + return response, err +} \ No newline at end of file diff --git a/proxy/proxy_list_test.go b/proxy/proxy_list_test.go new file mode 100644 index 0000000..8b875c5 --- /dev/null +++ b/proxy/proxy_list_test.go @@ -0,0 +1,73 @@ +package proxy_test + +import ( + "context" + "fmt" + "net/http" + "testing" + + "github.com/fivetran/go-fivetran/proxy" + + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestProxyListServiceDo(t *testing.T) { + // arrange + + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/proxy"). + ThenCall(func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, prepareProxyListResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewProxyList(). + Do(context.Background()) + + // assert + if err != nil { + 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) + assertProxyListResponse(t, response) +} + +func prepareProxyListResponse() string { + return fmt.Sprintf(`{ + "code": "Success", + "data": { + "items": [ + { + "id": "id", + "account_id": "account_id", + "registred_at": "registred_at", + "region": "region", + "token": "token", + "salt": "salt", + "created_by": "created_by", + "display_name": "display_name" + } + ], + "next_cursor": null + } +}`) +} + +func assertProxyListResponse(t *testing.T, response proxy.ProxyListResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Data.Items[0].Id, "id") + testutils.AssertEqual(t, response.Data.Items[0].AccountId, "account_id") + testutils.AssertEqual(t, response.Data.Items[0].RegistredAt, "registred_at") + testutils.AssertEqual(t, response.Data.Items[0].Region, "region") + testutils.AssertEqual(t, response.Data.Items[0].Token, "token") + testutils.AssertEqual(t, response.Data.Items[0].Salt, "salt") + testutils.AssertEqual(t, response.Data.Items[0].CreatedBy, "created_by") + testutils.AssertEqual(t, response.Data.Items[0].DisplayName, "display_name") +} \ No newline at end of file diff --git a/test_utils/test_utils.go b/test_utils/test_utils.go index ee562c3..8d3ed63 100644 --- a/test_utils/test_utils.go +++ b/test_utils/test_utils.go @@ -512,6 +512,7 @@ func CleanupAccount() { CleanupPrivateLinks() CleanupWebhooks() CleanupTeams() + CleanupProxy() } func IsPredefinedUserExist() bool { @@ -650,6 +651,24 @@ func CleanupTeams() { } } +func CleanupProxy() { + list, err := Client.NewProxyList().Do(context.Background()) + if err != nil { + log.Fatal(err) + } + + for _, proxy := range list.Data.Items { + _, err := Client.NewProxyDelete().ProxyId(proxy.Id).Do(context.Background()) + if err != nil && err.Error() != "status code: 404; expected: 200" { + log.Fatal(err) + } + } + + if list.Data.NextCursor != "" { + CleanupProxy() + } +} + func CreateTempExternalLogging(t *testing.T) string { t.Helper() externalLoggingId := CreateExternalLogging(t) @@ -952,6 +971,53 @@ func CreateUserGroup(t *testing.T, userId string, groupId string) { Role("Destination Analyst"). Do(context.Background()) + if err != nil { + t.Logf("%+v\n", created) + t.Error(err) + } +} + +func CreateProxy(t *testing.T) string { + t.Helper() + created, err := Client.NewProxyCreate(). + DisplayName("go_sdk_proxy_internal"). + GroupId(PredefinedGroupId). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", created) + t.Error(err) + } + return created.Data.AgentId +} + +func DeleteProxy(t *testing.T, id string) { + t.Helper() + deleted, err := Client.NewProxyDelete().ProxyId(id).Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", deleted) + t.Error(err) + } +} + +func DeleteProxyConnection(t *testing.T, proxyId string, connectionId string) { + t.Helper() + deleted, err := Client.NewProxyConnectionMembershipDelete().ProxyId(proxyId).ConnectionId(connectionId).Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", deleted) + t.Error(err) + } +} + +func CreateProxyConnection(t *testing.T, proxyId string, connectionId string) { + t.Helper() + created, err := Client.NewProxyConnectionMembershipCreate(). + ProxyId(proxyId). + ConnectionId(connectionId). + Do(context.Background()) + if err != nil { t.Logf("%+v\n", created) t.Error(err) diff --git a/tests/e2e/proxy_connection_membership_create_test.go b/tests/e2e/proxy_connection_membership_create_test.go new file mode 100644 index 0000000..6942c33 --- /dev/null +++ b/tests/e2e/proxy_connection_membership_create_test.go @@ -0,0 +1,32 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestNewProxyConnectionMembershipCreateE2E(t *testing.T) { + proxyId := testutils.CreateProxy(t) + connectionId := testutils.CreateConnector(t) + + created, err := testutils.Client.NewProxyConnectionMembershipCreate(). + ProxyId(proxyId). + ConnectionId(connectionId). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", created) + t.Error(err) + } + + testutils.AssertEqual(t, created.Code, "Success") + testutils.AssertNotEmpty(t, created.Message) + + t.Cleanup(func() { + testutils.DeleteProxyConnection(t, proxyId, connectionId) + testutils.DeleteConnector(t, connectionId) + testutils.DeleteProxy(t, proxyId) + }) +} diff --git a/tests/e2e/proxy_connection_membership_delete_test.go b/tests/e2e/proxy_connection_membership_delete_test.go new file mode 100644 index 0000000..fde9ace --- /dev/null +++ b/tests/e2e/proxy_connection_membership_delete_test.go @@ -0,0 +1,32 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestProxyConnectionMembershipDeleteE2E(t *testing.T) { + proxyId := testutils.CreateProxy(t) + connectionId := testutils.CreateConnector(t) + testutils.CreateProxyConnection(t, proxyId, connectionId) + + deleted, err := testutils.Client.NewProxyConnectionMembershipDelete(). + ProxyId(proxyId). + ConnectionId(connectionId). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", deleted) + t.Error(err) + } + + testutils.AssertEqual(t, deleted.Code, "Success") + testutils.AssertNotEmpty(t, deleted.Message) + + t.Cleanup(func() { + testutils.DeleteConnector(t, connectionId) + testutils.DeleteProxy(t, proxyId) + }) +} diff --git a/tests/e2e/proxy_connection_memberships_list_test.go b/tests/e2e/proxy_connection_memberships_list_test.go new file mode 100644 index 0000000..45b3bfc --- /dev/null +++ b/tests/e2e/proxy_connection_memberships_list_test.go @@ -0,0 +1,29 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestProxyConnectionMembershipsListE2E(t *testing.T) { + proxyId := testutils.CreateProxy(t) + connectionId := testutils.CreateConnector(t) + testutils.CreateProxyConnection(t, proxyId, connectionId) + + result, err := testutils.Client.NewProxyConnectionMembershipsList().ProxyId(proxyId).Do(context.Background()) + if err != nil { + t.Logf("%+v\n", result) + t.Error(err) + } + + testutils.AssertEqual(t, result.Code, "Success") + testutils.AssertEqual(t, result.Data.Items[0].ConnectionId, connectionId) + + t.Cleanup(func() { + testutils.DeleteProxyConnection(t, proxyId, connectionId) + testutils.DeleteConnector(t, connectionId) + testutils.DeleteProxy(t, proxyId) + }) +} diff --git a/tests/e2e/proxy_create_test.go b/tests/e2e/proxy_create_test.go new file mode 100644 index 0000000..aa572d2 --- /dev/null +++ b/tests/e2e/proxy_create_test.go @@ -0,0 +1,32 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestNewProxyCreateE2E(t *testing.T) { + groupId := testutils.CreateGroup(t) + created, err := testutils.Client.NewProxyCreate(). + DisplayName("go_sdk_test_proxy"). + GroupId(groupId). + Do(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.AssertNotEmpty(t, created.Data.AgentId) + testutils.AssertNotEmpty(t, created.Data.AuthToken) + testutils.AssertNotEmpty(t, created.Data.ProxyServerUri) + + t.Cleanup(func() { + testutils.DeleteProxy(t, created.Data.AgentId) + testutils.DeleteGroup(t, groupId) + }) +} diff --git a/tests/e2e/proxy_delete_test.go b/tests/e2e/proxy_delete_test.go new file mode 100644 index 0000000..4588a6f --- /dev/null +++ b/tests/e2e/proxy_delete_test.go @@ -0,0 +1,22 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestNewProxyDeleteE2E(t *testing.T) { + proxyId := testutils.CreateProxy(t) + + deleted, err := testutils.Client.NewProxyDelete().ProxyId(proxyId).Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", deleted) + t.Error(err) + } + + testutils.AssertEqual(t, deleted.Code, "Success") + testutils.AssertNotEmpty(t, deleted.Message) +} diff --git a/tests/e2e/proxy_details_test.go b/tests/e2e/proxy_details_test.go new file mode 100644 index 0000000..9429c0c --- /dev/null +++ b/tests/e2e/proxy_details_test.go @@ -0,0 +1,29 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestProxyDetailsE2E(t *testing.T) { + proxyId := testutils.CreateProxy(t) + + result, err := testutils.Client.NewProxyDetails().ProxyId(proxyId).Do(context.Background()) + if err != nil { + t.Logf("%+v\n", result) + t.Error(err) + } + + testutils.AssertEqual(t, result.Code, "Success") + testutils.AssertEqual(t, result.Data.Id, proxyId) + testutils.AssertNotEmpty(t, result.Data.AccountId) + testutils.AssertNotEmpty(t, result.Data.Region) + testutils.AssertNotEmpty(t, result.Data.Token) + testutils.AssertNotEmpty(t, result.Data.Salt) + testutils.AssertNotEmpty(t, result.Data.CreatedBy) + testutils.AssertNotEmpty(t, result.Data.DisplayName) + + t.Cleanup(func() { testutils.DeleteProxy(t, proxyId) }) +} diff --git a/tests/e2e/proxy_list_test.go b/tests/e2e/proxy_list_test.go new file mode 100644 index 0000000..a468da5 --- /dev/null +++ b/tests/e2e/proxy_list_test.go @@ -0,0 +1,29 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestProxyListE2E(t *testing.T) { + proxyId := testutils.CreateProxy(t) + + result, err := testutils.Client.NewProxyList().Do(context.Background()) + if err != nil { + t.Logf("%+v\n", result) + t.Error(err) + } + + testutils.AssertEqual(t, result.Code, "Success") + testutils.AssertEqual(t, result.Data.Items[0].Id, proxyId) + testutils.AssertNotEmpty(t, result.Data.Items[0].AccountId) + testutils.AssertNotEmpty(t, result.Data.Items[0].Region) + testutils.AssertNotEmpty(t, result.Data.Items[0].Token) + testutils.AssertNotEmpty(t, result.Data.Items[0].Salt) + testutils.AssertNotEmpty(t, result.Data.Items[0].CreatedBy) + testutils.AssertNotEmpty(t, result.Data.Items[0].DisplayName) + + t.Cleanup(func() { testutils.DeleteProxy(t, proxyId) }) +}