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

Bug: environment resource configuration field is affected by global s… #326

Merged
merged 2 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions client/configuration_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ func (client *ApiClient) ConfigurationVariablesByScope(scope Scope, scopeId stri
if err != nil {
return []ConfigurationVariable{}, err
}

if scope != ScopeGlobal {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RLRabinowitz - decided to fix the issue here. This covers much more use-cases.
I hope it makes sense: I filter out the global scope if the requested scope isn't global.

// Filter out global scopes. If a non global scope is requested.
filteredResult := []ConfigurationVariable{}
for _, variable := range result {
if variable.Scope != ScopeGlobal {
filteredResult = append(filteredResult, variable)
}
}
return filteredResult, nil
}

return result, nil
}

Expand Down
19 changes: 18 additions & 1 deletion client/configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ var _ = Describe("Configuration Variable", func() {
IsRequired: &isRequired,
}

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,
}

Describe("ConfigurationVariable", func() {
Describe("Schema", func() {
It("On schema type is free text, enum should be nil", func() {
Expand Down Expand Up @@ -247,7 +263,7 @@ var _ = Describe("Configuration Variable", func() {

Describe("ConfigurationVariablesByScope", func() {
var returnedVariables []ConfigurationVariable
mockVariables := []ConfigurationVariable{mockConfigurationVariable}
mockVariables := []ConfigurationVariable{mockConfigurationVariable, mockGlobalConfigurationVariable}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed. Added the use-case to the unit tests.

expectedParams := map[string]string{"organizationId": organizationId}

BeforeEach(func() {
Expand Down Expand Up @@ -287,6 +303,7 @@ var _ = Describe("Configuration Variable", func() {
*response = mockVariables
})
returnedVariables, _ = apiClient.ConfigurationVariablesByScope(Scope(scope), scopeId)
Expect(returnedVariables).To((Equal([]ConfigurationVariable{mockConfigurationVariable})))
httpCall.Times(1)
},
Entry("Template Scope", string(ScopeTemplate), "blueprintId"),
Expand Down