diff --git a/client/configuration_variable.go b/client/configuration_variable.go index 72ab236e..8530b2fd 100644 --- a/client/configuration_variable.go +++ b/client/configuration_variable.go @@ -85,16 +85,6 @@ func (client *ApiClient) ConfigurationVariablesById(id string) (ConfigurationVar return result, nil } -func filterOutConfigurationVariables(variables []ConfigurationVariable, scope Scope) []ConfigurationVariable { - filteredVariables := []ConfigurationVariable{} - for _, variable := range variables { - if variable.Scope != scope { - filteredVariables = append(filteredVariables, variable) - } - } - return filteredVariables -} - func (client *ApiClient) ConfigurationVariablesByScope(scope Scope, scopeId string) ([]ConfigurationVariable, error) { organizationId, err := client.OrganizationId() if err != nil { @@ -120,15 +110,15 @@ func (client *ApiClient) ConfigurationVariablesByScope(scope Scope, scopeId stri return []ConfigurationVariable{}, err } - // The API returns global and template scopes for environment (and other) scopes. Filter them out. - if scope != ScopeGlobal { - result = filterOutConfigurationVariables(result, ScopeGlobal) - if scope != ScopeTemplate { - result = filterOutConfigurationVariables(result, ScopeTemplate) + // The API returns variables of upper scopes. Filter them out. + var filteredVariables []ConfigurationVariable + for _, variable := range result { + if scopeId == variable.ScopeId && scope == variable.Scope { + filteredVariables = append(filteredVariables, variable) } } - return result, nil + return filteredVariables, nil } func (client *ApiClient) ConfigurationVariableCreate(params ConfigurationVariableCreateParams) (ConfigurationVariable, error) { diff --git a/client/configuration_variable_test.go b/client/configuration_variable_test.go index f15451ed..c722f7bf 100644 --- a/client/configuration_variable_test.go +++ b/client/configuration_variable_test.go @@ -38,23 +38,6 @@ var _ = Describe("Configuration Variable", func() { Regex: "regex", } - mockGlobalConfigurationVariable := ConfigurationVariable{ - Id: "config-var-id-789", - Name: "configName", - Description: "configDescription", - Value: "configValue", - OrganizationId: organizationId, - IsSensitive: &isSensitive, - Scope: ScopeGlobal, - Type: &varType, - ScopeId: "project-123", - UserId: "user|123", - Schema: &schema, - IsReadOnly: &isReadOnly, - IsRequired: &isRequired, - Regex: "regex", - } - mockTemplateConfigurationVariable := ConfigurationVariable{ Id: "config-var-id-1111", Name: "ignore", @@ -62,6 +45,7 @@ var _ = Describe("Configuration Variable", func() { Value: "ignore", OrganizationId: organizationId, Scope: ScopeTemplate, + ScopeId: "scope-id", } Describe("ConfigurationVariable", func() { @@ -277,9 +261,11 @@ var _ = Describe("Configuration Variable", func() { }) Describe("ConfigurationVariablesByScope", func() { + scopeId := mockTemplateConfigurationVariable.ScopeId + var returnedVariables []ConfigurationVariable - mockVariables := []ConfigurationVariable{mockConfigurationVariable, mockGlobalConfigurationVariable, mockTemplateConfigurationVariable} - expectedParams := map[string]string{"organizationId": organizationId} + mockVariables := []ConfigurationVariable{mockTemplateConfigurationVariable} + expectedParams := map[string]string{"organizationId": organizationId, "blueprintId": scopeId} BeforeEach(func() { mockOrganizationIdCall(organizationId) @@ -289,7 +275,7 @@ var _ = Describe("Configuration Variable", func() { Do(func(path string, request interface{}, response *[]ConfigurationVariable) { *response = mockVariables }) - returnedVariables, _ = apiClient.ConfigurationVariablesByScope(ScopeGlobal, "") + returnedVariables, _ = apiClient.ConfigurationVariablesByScope(ScopeTemplate, scopeId) }) It("Should send GET request with expected params", func() { @@ -303,32 +289,5 @@ var _ = Describe("Configuration Variable", func() { It("Should return variables", func() { Expect(returnedVariables).To(Equal(mockVariables)) }) - - DescribeTable("Different Scopes", - func(scope string, expectedFieldName string) { - scopeId := expectedFieldName + "-id" - expectedParams := map[string]string{ - "organizationId": organizationId, - expectedFieldName: scopeId, - } - - httpCall = mockHttpClient.EXPECT(). - Get("/configuration", expectedParams, gomock.Any()). - Do(func(path string, request interface{}, response *[]ConfigurationVariable) { - *response = mockVariables - }) - returnedVariables, _ = apiClient.ConfigurationVariablesByScope(Scope(scope), scopeId) - if scope == string(ScopeTemplate) { - Expect(returnedVariables).To((Equal([]ConfigurationVariable{mockConfigurationVariable, mockTemplateConfigurationVariable}))) - } else { - Expect(returnedVariables).To((Equal([]ConfigurationVariable{mockConfigurationVariable}))) - } - httpCall.Times(1) - }, - Entry("Template Scope", string(ScopeTemplate), "blueprintId"), - Entry("Project Scope", string(ScopeProject), "projectId"), - Entry("Environment Scope", string(ScopeEnvironment), "environmentId"), - Entry("Project Scope", string(ScopeDeploymentLog), "deploymentLogId"), - ) }) })