Skip to content

Commit

Permalink
adds tests for the new AllowedRegexpPrefixes config
Browse files Browse the repository at this point in the history
  • Loading branch information
bmbferreira committed Nov 5, 2021
1 parent 6f9c3e2 commit 46eb1a1
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/events/yaml/raw/repo_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ workflows:
policy_check:
steps: []
apply:
steps: []`,
steps: []
allowed_regexp_prefixes:
- dev/
- staging/`,
exp: raw.RepoCfg{
Version: Int(3),
Automerge: Bool(true),
Expand Down Expand Up @@ -176,6 +179,7 @@ workflows:
},
},
},
AllowedRegexpPrefixes: []string{"dev/", "staging/"},
},
},
}
Expand Down
175 changes: 175 additions & 0 deletions server/events/yaml/valid/repo_cfg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package valid_test

import (
"testing"

validation "github.com/go-ozzo/ozzo-validation"
version "github.com/hashicorp/go-version"
"github.com/runatlantis/atlantis/server/events/yaml/valid"
. "github.com/runatlantis/atlantis/testing"
)

func TestConfig_FindProjectsByDir(t *testing.T) {
tfVersion, _ := version.NewVersion("v0.11.0")
cases := []struct {
description string
nameRegex string
input valid.RepoCfg
expProjects []valid.Project
}{
{
description: "Find projects with 'dev' prefix as allowed prefix",
nameRegex: "dev.*",
input: valid.RepoCfg{
Version: 3,
Projects: []valid.Project{
{
Dir: ".",
Name: String("dev_terragrunt_myproject"),
Workspace: "myworkspace",
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: false,
},
ApplyRequirements: []string{"approved"},
},
},
Workflows: map[string]valid.Workflow{
"myworkflow": {
Name: "myworkflow",
Apply: valid.DefaultApplyStage,
Plan: valid.DefaultPlanStage,
PolicyCheck: valid.DefaultPolicyCheckStage,
},
},
AllowedRegexpPrefixes: []string{"dev", "staging"},
},
expProjects: []valid.Project{
{
Dir: ".",
Name: String("dev_terragrunt_myproject"),
Workspace: "myworkspace",
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: false,
},
ApplyRequirements: []string{"approved"},
},
},
},
{
description: "Only find projects with allowed prefix",
nameRegex: ".*",
input: valid.RepoCfg{
Version: 3,
Projects: []valid.Project{
{
Dir: ".",
Name: String("dev_terragrunt_myproject"),
Workspace: "myworkspace",
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: false,
},
ApplyRequirements: []string{"approved"},
},
{
Dir: ".",
Name: String("staging_terragrunt_myproject"),
Workspace: "myworkspace",
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: false,
},
ApplyRequirements: []string{"approved"},
},
},
Workflows: map[string]valid.Workflow{
"myworkflow": {
Name: "myworkflow",
Apply: valid.DefaultApplyStage,
Plan: valid.DefaultPlanStage,
PolicyCheck: valid.DefaultPolicyCheckStage,
},
},
AllowedRegexpPrefixes: []string{"dev", "staging"},
},
expProjects: nil,
},
{
description: "Find all projects without restrictions of allowed prefix",
nameRegex: ".*",
input: valid.RepoCfg{
Version: 3,
Projects: []valid.Project{
{
Dir: ".",
Name: String("dev_terragrunt_myproject"),
Workspace: "myworkspace",
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: false,
},
ApplyRequirements: []string{"approved"},
},
{
Dir: ".",
Name: String("staging_terragrunt_myproject"),
Workspace: "myworkspace",
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: false,
},
ApplyRequirements: []string{"approved"},
},
},
Workflows: map[string]valid.Workflow{
"myworkflow": {
Name: "myworkflow",
Apply: valid.DefaultApplyStage,
Plan: valid.DefaultPlanStage,
PolicyCheck: valid.DefaultPolicyCheckStage,
},
},
AllowedRegexpPrefixes: nil,
},
expProjects: []valid.Project{
{
Dir: ".",
Name: String("dev_terragrunt_myproject"),
Workspace: "myworkspace",
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: false,
},
ApplyRequirements: []string{"approved"},
},
{
Dir: ".",
Name: String("staging_terragrunt_myproject"),
Workspace: "myworkspace",
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: false,
},
ApplyRequirements: []string{"approved"},
},
},
},
}
validation.ErrorTag = "yaml"
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
projects := c.input.FindProjectsByName(c.nameRegex)
Equals(t, c.expProjects, projects)
})
}
}

0 comments on commit 46eb1a1

Please sign in to comment.