Skip to content

Commit

Permalink
Feat: add API calls for configuration set assignment (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber authored May 22, 2024
1 parent e37247b commit dbeba01
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ attic
.vscode/
.idea/
tf

# macosx
.DS_Store
2 changes: 2 additions & 0 deletions client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ type ApiClientInterface interface {
ConfigurationSet(id string) (*ConfigurationSet, error)
ConfigurationSetDelete(id string) error
ConfigurationVariablesBySetId(setId string) ([]ConfigurationVariable, error)
AssignConfigurationSets(scope string, scopeId string, sets []string) error
UnassignConfigurationSets(scope string, scopeId string, sets []string) error
}

func NewApiClient(client http.HttpClientInterface, defaultOrganizationId string) ApiClientInterface {
Expand Down
28 changes: 28 additions & 0 deletions client/api_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions client/configuration_set_assignment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package client

import (
"fmt"
"strings"
)

func (client *ApiClient) AssignConfigurationSets(scope string, scopeId string, sets []string) error {
setIds := strings.Join(sets, ",")
url := fmt.Sprintf("/configuration-sets/assignments/%s/%s?setIds=%s", scope, scopeId, setIds)

return client.http.Post(url, nil, nil)
}

func (client *ApiClient) UnassignConfigurationSets(scope string, scopeId string, sets []string) error {
setIds := strings.Join(sets, ",")
url := fmt.Sprintf("/configuration-sets/assignments/%s/%s", scope, scopeId)

return client.http.Delete(url, map[string]string{"setIds": setIds})
}
31 changes: 31 additions & 0 deletions client/configuration_set_assignment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package client_test

import (
. "github.com/onsi/ginkgo"
)

var _ = Describe("Configuration Set", func() {
scope := "environment"
scopeId := "12345"
setIds := []string{"1", "2", "3"}

Describe("assign configuration sets", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Post("/configuration-sets/assignments/environment/12345?setIds=1,2,3", nil, nil).Times(1)
apiClient.AssignConfigurationSets(scope, scopeId, setIds)
})

It("Should send post request", func() {})
})

Describe("unassign configuration sets", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Delete("/configuration-sets/assignments/environment/12345", map[string]string{
"setIds": "1,2,3",
}).Times(1)
apiClient.UnassignConfigurationSets(scope, scopeId, setIds)
})

It("Should send delete request", func() {})
})
})

0 comments on commit dbeba01

Please sign in to comment.