Skip to content

Commit

Permalink
Fix integration and go-lint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chanaMovshowich committed Jun 9, 2024
1 parent 1d9dce7 commit c44c968
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
30 changes: 18 additions & 12 deletions src/common/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +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{}
runner.Init(&options)
runner.parsers[0].ParseFile(options.Directory)
utils.AppendSkipedByCommentToRunnerSkippedResources(&runner.skippedResources)
result := make([]string, 0)
result = append(result, "aws_instance.example_instance")
assert.Equal(t, result, runner.skippedResources)
})
options := clioptions.TagOptions{

Check failure on line 226 in src/common/runner/runner_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci-lint] reported by reviewdog 🐶 File is not `gofmt`-ed with `-s` (gofmt) Raw Output: src/common/runner/runner_test.go:226: File is not `gofmt`-ed with `-s` (gofmt) 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)
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)
})

t.Run("Test skip resource - cloudformation", func(t *testing.T) {
runner := Runner{}
Expand Down
5 changes: 5 additions & 0 deletions src/common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"regexp"
"strings"
"unicode"
"sync"

"github.com/bridgecrewio/yor/src/common"
"github.com/bridgecrewio/yor/src/common/logger"
Expand All @@ -20,6 +21,10 @@ var RemoveGcpInvalidChars = regexp.MustCompile(`[^\p{Ll}\p{Lo}\p{N}_-]`)
var SkipResourcesByComment = make([]string, 0)

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

*skippedResources = append(*skippedResources, SkipResourcesByComment...)
SkipResourcesByComment = SkipResourcesByComment[:0]
}
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 @@ -179,7 +179,7 @@ func (p *TerraformParser) ParseFile(filePath string) ([]structure.IBlock, error)
line := terraformBlock.GetLines().Start
if line > 1 && line <= len(lines) {
lineAbove := lines[line-2]
if strings.ToUpper(strings.TrimSpace(lineAbove))== "#YOR:SKIPALL" {
if strings.ToUpper(strings.TrimSpace(lineAbove)) == "#YOR:SKIPALL" {
skipAll = true
}

Check failure on line 185 in src/terraform/structure/terraform_parser.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci-lint] reported by reviewdog 🐶 File is not `gofmt`-ed with `-s` (gofmt) Raw Output: src/terraform/structure/terraform_parser.go:185: File is not `gofmt`-ed with `-s` (gofmt)
Expand Down

0 comments on commit c44c968

Please sign in to comment.