Skip to content

Commit

Permalink
add test in run_test for scan and skip rules using config file
Browse files Browse the repository at this point in the history
  • Loading branch information
patilpankaj212 committed Dec 23, 2020
1 parent 2ca27b9 commit b6db0ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package cli

import (
"fmt"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -51,6 +50,7 @@ func TestRun(t *testing.T) {
testDirPath := "testdata/run-test"
kustomizeTestDirPath := testDirPath + "/kustomize-test"
testTerraformFilePath := testDirPath + "/config-only.tf"
ruleSlice := []string{"AWS.ECR.DataSecurity.High.0579", "AWS.SecurityGroup.NetworkPortsSecurity.Low.0561"}

table := []struct {
name string
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestRun(t *testing.T) {
policyType: []string{"all"},
iacDirPath: testDirPath,
outputType: "json",
skipRules: []string{"AWS.ECR.DataSecurity.High.0579", "AWS.SecurityGroup.NetworkPortsSecurity.Low.0561"},
skipRules: ruleSlice,
},
},
{
Expand All @@ -159,16 +159,22 @@ func TestRun(t *testing.T) {
policyType: []string{"all"},
iacDirPath: testDirPath,
outputType: "yaml",
scanRules: []string{"AWS.ECR.DataSecurity.High.0579", "AWS.SecurityGroup.NetworkPortsSecurity.Low.0561"},
scanRules: ruleSlice,
},
},
{
name: "config file with rules",
scanOptions: &ScanOptions{
policyType: []string{"all"},
iacDirPath: testDirPath,
outputType: "yaml",
configFile: "testdata/configFile.toml",
},
},
}

for _, tt := range table {
t.Run(tt.name, func(t *testing.T) {
if tt.name == "run with scan rules" {
fmt.Println()
}
err := tt.scanOptions.Run()
if (err != nil) != tt.wantErr {
t.Errorf("ScanOptions.Run() error = %v, wantErr %v", err, tt.wantErr)
Expand Down
7 changes: 7 additions & 0 deletions pkg/cli/testdata/configFile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[rules]
scan-rules = [
"AWS.ECR.DataSecurity.High.0579"
]
skip-rules = [
"AWS.SecurityGroup.NetworkPortsSecurity.Low.0561"
]

0 comments on commit b6db0ae

Please sign in to comment.