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

feat(resource): support directory update #284

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions internal/btpcli/facade_accounts_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,47 @@ func (f *accountsDirectoryFacade) Get(ctx context.Context, directoryId string) (
}

type DirectoryCreateInput struct {
DisplayName string `btpcli:"displayName"`
Description *string `btpcli:"description"`
ParentID *string `btpcli:"parentID"`
Subdomain *string `btpcli:"subdomain"`
Labels map[string][]string `btpcli:"labels"`
DisplayName string `btpcli:"displayName"`
Description *string `btpcli:"description"`
ParentID *string `btpcli:"parentID"`
Subdomain *string `btpcli:"subdomain"`
Labels map[string][]string `btpcli:"labels"`
Globalaccount string `btpcli:"globalAccount"`
//DirectoryAdmins string `btpcli:"directoryAdmins"`
}

type DirectoryUpdateInput struct {
DirectoryId string `btpcli:"directoryID"`
Globalaccount string `btpcli:"globalAccount"`
DisplayName *string `btpcli:"displayName"`
Description *string `btpcli:"description"`
Labels map[string][]string `btpcli:"labels"`
}

func (f *accountsDirectoryFacade) Create(ctx context.Context, args *DirectoryCreateInput) (cis.DirectoryResponseObject, CommandResponse, error) {
args.Globalaccount = f.cliClient.GetGlobalAccountSubdomain()

params, err := tfutils.ToBTPCLIParamsMap(args)

if err != nil {
return cis.DirectoryResponseObject{}, CommandResponse{}, err
}

params["globalAccount"] = f.cliClient.GetGlobalAccountSubdomain()

return doExecute[cis.DirectoryResponseObject](f.cliClient, ctx, NewCreateRequest(f.getCommand(), params))
}

func (f *accountsDirectoryFacade) Update(ctx context.Context, args *DirectoryUpdateInput) (cis.DirectoryResponseObject, CommandResponse, error) {
args.Globalaccount = f.cliClient.GetGlobalAccountSubdomain()

params, err := tfutils.ToBTPCLIParamsMap(args)

if err != nil {
return cis.DirectoryResponseObject{}, CommandResponse{}, err
}

return doExecute[cis.DirectoryResponseObject](f.cliClient, ctx, NewUpdateRequest(f.getCommand(), params))
}

func (f *accountsDirectoryFacade) Delete(ctx context.Context, directoryId string) (cis.DirectoryResponseObject, CommandResponse, error) {
return doExecute[cis.DirectoryResponseObject](f.cliClient, ctx, NewDeleteRequest(f.getCommand(), map[string]string{
"globalAccount": f.cliClient.GetGlobalAccountSubdomain(),
Expand Down
49 changes: 45 additions & 4 deletions internal/btpcli/facade_accounts_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestAccountsDirectoryFacade_Get(t *testing.T) {

func TestAccountsDirectoryFacade_Create(t *testing.T) {
command := "accounts/directory"
globalAccount := "795b53bb-a3f0-4769-adf0-26173282a975"

displayName := "my-directory"
description := "a description"
Expand All @@ -47,14 +48,14 @@ func TestAccountsDirectoryFacade_Create(t *testing.T) {
srvCalled = true

assertCall(t, r, command, ActionCreate, map[string]string{
"globalAccount": "795b53bb-a3f0-4769-adf0-26173282a975",
"displayName": "my-directory",
"globalAccount": globalAccount,
"displayName": displayName,
})
}))
defer srv.Close()

_, res, err := uut.Accounts.Directory.Create(context.TODO(), &DirectoryCreateInput{
DisplayName: "my-directory",
DisplayName: displayName,
})

if assert.True(t, srvCalled) && assert.NoError(t, err) {
Expand All @@ -68,11 +69,12 @@ func TestAccountsDirectoryFacade_Create(t *testing.T) {
srvCalled = true

assertCall(t, r, command, ActionCreate, map[string]string{
"globalAccount": "795b53bb-a3f0-4769-adf0-26173282a975",
"globalAccount": globalAccount,
"displayName": displayName,
"description": description,
"subdomain": subdomain,
"parentID": parentId,
"labels": "{}",
})
}))
defer srv.Close()
Expand All @@ -82,6 +84,45 @@ func TestAccountsDirectoryFacade_Create(t *testing.T) {
Description: &description,
Subdomain: &subdomain,
ParentID: &parentId,
Labels: map[string][]string{},
})

if assert.True(t, srvCalled) && assert.NoError(t, err) {
assert.Equal(t, 200, res.StatusCode)
}
})
}

func TestAccountsDirectoryFacade_Update(t *testing.T) {
command := "accounts/directory"
globalAccount := "795b53bb-a3f0-4769-adf0-26173282a975"

directoryId := "6aa64c2f-38c1-49a9-b2e8-cf9fea769b7f"
displayName := "my-directory"
description := "a description"

t.Run("constructs the CLI params correctly", func(t *testing.T) {
var srvCalled bool

uut, srv := prepareClientFacadeForTest(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srvCalled = true

assertCall(t, r, command, ActionUpdate, map[string]string{
"globalAccount": globalAccount,
"directoryID": directoryId,
"displayName": displayName,
"description": description,
"labels": "{}",
})

}))
defer srv.Close()

_, res, err := uut.Accounts.Directory.Update(context.TODO(), &DirectoryUpdateInput{
DirectoryId: directoryId,
DisplayName: &displayName,
Description: &description,
Labels: map[string][]string{},
})

if assert.True(t, srvCalled) && assert.NoError(t, err) {
Expand Down
Loading
Loading