Skip to content

Commit

Permalink
service-account endpoint support
Browse files Browse the repository at this point in the history
  • Loading branch information
beevital committed Nov 17, 2023
1 parent f5b45f0 commit 08653bf
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,7 @@ func (c *Client) NewGroupsList() *groups.GroupsListService {
func (c *Client) NewGroupSshPublicKey() *groups.GroupSshKeyService {
return &groups.GroupSshKeyService{HttpService: c.NewHttpService()}
}

func (c *Client) NewGroupServiceAccount() *groups.GroupServiceAccountService {
return &groups.GroupServiceAccountService{HttpService: c.NewHttpService()}
}
7 changes: 7 additions & 0 deletions groups/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ type GroupSshKeyResponse struct {
}
}

type GroupServiceAccountResponse struct {
common.CommonResponse
Data struct {
ServiceAccount string `json:"service_account"`
}
}

type GroupListConnectorsResponse struct {
common.CommonResponse
Data struct {
Expand Down
25 changes: 25 additions & 0 deletions groups/group_service_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package groups

import (
"context"
"fmt"

httputils "github.com/fivetran/go-fivetran/http_utils"
)

type GroupServiceAccountService struct {
httputils.HttpService
groupID *string
}

func (s *GroupServiceAccountService) GroupID(value string) *GroupServiceAccountService {
s.groupID = &value
return s
}

func (s *GroupServiceAccountService) Do(ctx context.Context) (GroupServiceAccountResponse, error) {
var response GroupServiceAccountResponse
url := fmt.Sprintf("/groups/%v/service-account", *s.groupID)
err := s.HttpService.Do(ctx, "GET", url, nil, nil, 200, &response)
return response, err
}
49 changes: 49 additions & 0 deletions groups/group_service_account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package groups_test

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

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

func TestGroupServiceAccountServiceDo(t *testing.T) {
// arrange
serviceAccount := "[email protected]"

ftClient, mockClient := tests.CreateTestClient()
handler := mockClient.When(http.MethodGet, "/v1/groups/"+EXPECTED_GROUP_ID+"/service-account").
ThenCall(func(req *http.Request) (*http.Response, error) {
response := mock.NewResponse(req, http.StatusOK, fmt.Sprintf(
`{
"code": "Success",
"data": {
"service_account": "%v"
}
}`,
serviceAccount))
return response, nil
})

// act
response, err := ftClient.NewGroupServiceAccount().
GroupID(EXPECTED_GROUP_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)

testutils.AssertEqual(t, response.Code, "Success")
testutils.AssertEqual(t, response.Data.ServiceAccount, serviceAccount)
}

0 comments on commit 08653bf

Please sign in to comment.