Skip to content

Commit

Permalink
feat(resource): support update for subaccount_environment_instance re…
Browse files Browse the repository at this point in the history
…source

Also: add test utility for simple (not-)contains checks on resource attributes

Resolves #100
  • Loading branch information
kuntzed committed Jul 20, 2023
1 parent fbb7fee commit 4946302
Show file tree
Hide file tree
Showing 6 changed files with 5,907 additions and 18 deletions.
9 changes: 9 additions & 0 deletions internal/btpcli/facade_accounts_environment_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func (f *accountsEnvironmentInstanceFacade) Create(ctx context.Context, args *Su
return doExecute[provisioning.EnvironmentInstanceResponseObject](f.cliClient, ctx, NewCreateRequest(f.getCommand(), params))
}

func (f *accountsEnvironmentInstanceFacade) Update(ctx context.Context, subaccountId string, environmentId string, plan string, parameters string) (struct{}, CommandResponse, error) {
return doExecute[struct{}](f.cliClient, ctx, NewUpdateRequest(f.getCommand(), map[string]string{
"subaccount": subaccountId,
"environmentID": environmentId,
"plan": plan,
"parameters": parameters,
}))
}

func (f *accountsEnvironmentInstanceFacade) Delete(ctx context.Context, subaccountId string, environmentId string) (provisioning.EnvironmentInstanceResponseObject, CommandResponse, error) {
return doExecute[provisioning.EnvironmentInstanceResponseObject](f.cliClient, ctx, NewDeleteRequest(f.getCommand(), map[string]string{
"subaccount": subaccountId,
Expand Down
31 changes: 31 additions & 0 deletions internal/btpcli/facade_accounts_environment_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,37 @@ func TestAccountsEnvironmentInstanceFacade_Create(t *testing.T) {
})
}

func TestAccountsEnvironmentInstanceFacade_Update(t *testing.T) {
command := "accounts/environment-instance"

environmentId := "cloudfoundry"
plan := "free"
parameters := "{}"
subaccountId := "6aa64c2f-38c1-49a9-b2e8-cf9fea769b7f"

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{
"subaccount": subaccountId,
"environmentID": environmentId,
"plan": plan,
"parameters": parameters,
})
}))
defer srv.Close()

_, res, err := uut.Accounts.EnvironmentInstance.Update(context.TODO(), subaccountId, environmentId, plan, parameters)

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

func TestAccountsEnvironmentInstanceFacade_Delete(t *testing.T) {
command := "accounts/environment-instance"

Expand Down
Loading

0 comments on commit 4946302

Please sign in to comment.