Skip to content

Commit

Permalink
Merge pull request #230 from OctopusDeploy/tl/support-process-variabl…
Browse files Browse the repository at this point in the history
…e-scope

chore: Support process scoped variable scope matching
  • Loading branch information
tleed5 authored Jan 9, 2024
2 parents 7e3ee6f + d25cc85 commit 3b703ae
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if err != nil {

Operations like `Add`, `DeleteByID`, `GetByID`, and `Update` are supported by most services that are exposed through the client if not exposed in the package. These operations are configured at runtime since the Octopus REST API is hypermedia-driven.

Numerous code samples that showcase the API and this client are available in the [examples](/examples) directory. There are also many [integration](/integration) and unit tests available to examine that demonstrate the capabilities of this API client.
Numerous code samples that showcase the API and this client are available in the [examples](/examples) directory. There are also many [integration](/test) and unit tests available to examine that demonstrate the capabilities of this API client.

## 🤝 Contributions

Expand Down
9 changes: 9 additions & 0 deletions pkg/variables/variable_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,15 @@ func MatchesScope(variableScope VariableScope, definedScope *VariableScope) (boo
}
}

for _, p1 := range definedScope.ProcessOwners {
for _, p2 := range variableScope.ProcessOwners {
if p1 == p2 {
matched = true
matchedScopes.ProcessOwners = append(matchedScopes.ProcessOwners, p1)
}
}
}

return matched, &matchedScopes, nil
}

Expand Down
96 changes: 96 additions & 0 deletions pkg/variables/variable_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,99 @@ func TestVariableServiceDeleteSingleWithEmptyID(t *testing.T) {
require.Error(t, err)
require.NotNil(t, variableSet)
}

func TestMatchesScopeWithEmptyVariableScope(t *testing.T) {
variableScope := VariableScope{
Environments: nil,
Machines: nil,
Actions: nil,
Roles: nil,
Channels: nil,
TenantTags: nil,
ProcessOwners: nil,
}
definedScope := &VariableScope{
Environments: []string{"env-1"},
Machines: []string{"machine-1"},
Actions: []string{"action-1"},
Roles: []string{"role-1"},
Channels: []string{"channel-1"},
TenantTags: []string{"tenant-1"},
ProcessOwners: []string{"process-1"},
}

match, matchedScope, err := MatchesScope(variableScope, definedScope)
require.Nil(t, err)
require.False(t, match)
require.Nil(t, matchedScope.Environments)
require.Nil(t, matchedScope.Machines)
require.Nil(t, matchedScope.Actions)
require.Nil(t, matchedScope.Roles)
require.Nil(t, matchedScope.Channels)
require.Nil(t, matchedScope.TenantTags)
require.Nil(t, matchedScope.ProcessOwners)
}

func TestMatchesScopeWithNonMatchingVariableScope(t *testing.T) {
variableScope := VariableScope{
Environments: []string{"env-1"},
Machines: []string{"machine-1"},
Actions: []string{"action-1"},
Roles: []string{"role-1"},
Channels: []string{"channel-1"},
TenantTags: []string{"tenant-1"},
ProcessOwners: []string{"process-1"},
}
definedScope := &VariableScope{
Environments: []string{"env-2"},
Machines: []string{"machine-2"},
Actions: []string{"action-2"},
Roles: []string{"role-2"},
Channels: []string{"channel-2"},
TenantTags: []string{"tenant-2"},
ProcessOwners: []string{"process-2"},
}

match, matchedScope, err := MatchesScope(variableScope, definedScope)
require.Nil(t, err)
require.False(t, match)
require.Nil(t, matchedScope.Environments)
require.Nil(t, matchedScope.Machines)
require.Nil(t, matchedScope.Actions)
require.Nil(t, matchedScope.Roles)
require.Nil(t, matchedScope.Channels)
require.Nil(t, matchedScope.TenantTags)
require.Nil(t, matchedScope.ProcessOwners)
}

func TestMatchesScopeWithMatchingVariableScope(t *testing.T) {
variableScope := VariableScope{
Environments: []string{"env-1"},
Machines: []string{"machine-1"},
Actions: []string{"action-1"},
Roles: []string{"role-1"},
Channels: []string{"channel-1"},
TenantTags: []string{"tenant-1"},
ProcessOwners: []string{"process-1"},
}
definedScope := &VariableScope{
Environments: []string{"env-1"},
Machines: []string{"machine-1"},
Actions: []string{"action-1"},
Roles: []string{"role-1"},
Channels: []string{"channel-1"},
TenantTags: []string{"tenant-1"},
ProcessOwners: []string{"process-1"},
}

match, matchedScope, err := MatchesScope(variableScope, definedScope)
require.Nil(t, err)
require.True(t, match)
require.ElementsMatch(t, matchedScope.Environments, variableScope.Environments)
require.ElementsMatch(t, matchedScope.Machines, variableScope.Machines)
require.ElementsMatch(t, matchedScope.Actions, variableScope.Actions)
require.ElementsMatch(t, matchedScope.Roles, variableScope.Roles)
require.ElementsMatch(t, matchedScope.Channels, variableScope.Channels)
require.ElementsMatch(t, matchedScope.TenantTags, variableScope.TenantTags)
require.ElementsMatch(t, matchedScope.ProcessOwners, variableScope.ProcessOwners)
}

0 comments on commit 3b703ae

Please sign in to comment.