Skip to content

Commit

Permalink
Added a test of a regular and sensitive variables sharing a name
Browse files Browse the repository at this point in the history
  • Loading branch information
mcasperson committed Jul 31, 2024
1 parent 561c575 commit 17b7b14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 11 additions & 3 deletions octoterrawiz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ func TestProjectSpreadVariables(t *testing.T) {
t.Fatalf("Error getting project variable set: %v", err)
}

if len(variableSet.Variables) != 10 {
t.Fatalf("Expected 10 variables, got %v", len(variableSet.Variables))
if len(variableSet.Variables) != 11 {
t.Fatalf("Expected 11 variables, got %v", len(variableSet.Variables))
}

// The AWS account variable must be unaltered
Expand All @@ -234,6 +234,13 @@ func TestProjectSpreadVariables(t *testing.T) {
t.Fatalf("Expected 1 AWS account variable")
}

// The regular variable that shares the name with the sensitive variables must be unchanged
if len(lo.Filter(variableSet.Variables, func(item *variables.Variable, index int) bool {
return item.Name == "SensitiveVariable" && item.Type == "String" && *item.Value == "RegularVariable"
})) != 1 {
t.Fatalf("Expected 1 unchanged regular variable")
}

// All sensitive variables must be unscoped
if len(lo.Filter(variableSet.Variables, func(item *variables.Variable, index int) bool {
return item.IsSensitive && !item.Scope.IsEmpty()
Expand All @@ -253,7 +260,8 @@ func TestProjectSpreadVariables(t *testing.T) {
// The three sensitive variables that shared a name must now have 4 regular variables each scoped
// to an environment or are unscoped
originalVariables := lo.Filter(variableSet.Variables, func(item *variables.Variable, index int) bool {
return item.Name == "SensitiveVariable" && !item.IsSensitive && (len(item.Scope.Environments) == 1 || len(item.Scope.Environments) == 0)
// we're not testing the regular variable with the value "RegularVariable", as this was never modified
return item.Name == "SensitiveVariable" && !item.IsSensitive && (len(item.Scope.Environments) == 1 || len(item.Scope.Environments) == 0) && *item.Value != "RegularVariable"
})

if len(originalVariables) != 4 {
Expand Down
8 changes: 8 additions & 0 deletions terraform/3-simpleproject/project.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ resource "octopusdeploy_variable" "sensitive_var_3" {
}
}

resource "octopusdeploy_variable" "sensitive_var_4" {
owner_id = octopusdeploy_project.deploy_frontend_project.id
type = "String"
name = "SensitiveVariable"
value = "RegularVariable"
is_sensitive = false
}

resource "octopusdeploy_variable" "amazon_web_services_account_variable" {
owner_id = octopusdeploy_project.deploy_frontend_project.id
type = "AmazonWebServicesAccount"
Expand Down

0 comments on commit 17b7b14

Please sign in to comment.