Skip to content

Commit

Permalink
Fix integration_test and go-lint tests 2
Browse files Browse the repository at this point in the history
  • Loading branch information
chanaMovshowich committed Jun 9, 2024
1 parent c44c968 commit 1fe6d9f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
34 changes: 17 additions & 17 deletions src/common/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,24 @@ func TestRunnerInternals(t *testing.T) {
})

t.Run("Test skip resource by comment", func(t *testing.T) {
options := clioptions.TagOptions{
Directory: "../../../tests/terraform/skipComment/skipOne.tf",
Parsers: []string{"Terraform"},
}
runner := Runner{}
err := runner.Init(&options)
if err != nil {
t.Error(err)
}
tfBlocks, err := runner.parsers[0].ParseFile(options.Directory)
if err != nil {
t.Error(err)
}
assert.Equal(t, 3, len(tfBlocks))
utils.AppendSkipedByCommentToRunnerSkippedResources(&runner.skippedResources)
options := clioptions.TagOptions{
Directory: "../../../tests/terraform/skipComment/skipOne.tf",
Parsers: []string{"Terraform"},
}
runner := Runner{}
err := runner.Init(&options)
if err != nil {
t.Error(err)
}
tfBlocks, err := runner.parsers[0].ParseFile(options.Directory)
if err != nil {
t.Error(err)
}
assert.Equal(t, 3, len(tfBlocks))
utils.AppendSkipedByCommentToRunnerSkippedResources(&runner.skippedResources)
result := []string{"aws_instance.example_instance"}
assert.Equal(t, result, runner.skippedResources)
})
assert.Equal(t, result, runner.skippedResources)
})

t.Run("Test skip resource - cloudformation", func(t *testing.T) {
runner := Runner{}
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
// RemoveGcpInvalidChars Source of regex: https://cloud.google.com/compute/docs/labeling-resources
var RemoveGcpInvalidChars = regexp.MustCompile(`[^\p{Ll}\p{Lo}\p{N}_-]`)
var SkipResourcesByComment = make([]string, 0)
var mutex sync.Mutex

func AppendSkipedByCommentToRunnerSkippedResources(skippedResources *[]string) {
var mutex sync.Mutex
mutex.Lock()
defer mutex.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion src/terraform/structure/terraform_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (p *TerraformParser) ParseFile(filePath string) ([]structure.IBlock, error)
if strings.ToUpper(strings.TrimSpace(lineAbove)) == "#YOR:SKIPALL" {
skipAll = true
}

if strings.ToUpper(strings.TrimSpace(lineAbove)) == "#YOR:SKIP" || skipAll {
utils.SkipResourcesByComment = append(utils.SkipResourcesByComment, terraformBlock.GetResourceID())
}
Expand Down

0 comments on commit 1fe6d9f

Please sign in to comment.