Skip to content

Commit

Permalink
test: calc cache key with detection priority
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Aug 2, 2024
1 parent 67b80d3 commit 1ce2e4b
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions pkg/cache/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ import (

"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
"github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/aquasecurity/trivy/pkg/fanal/walker"
"github.com/aquasecurity/trivy/pkg/misconf"
)

func TestCalcKey(t *testing.T) {
type args struct {
key string
analyzerVersions analyzer.Versions
hookVersions map[string]int
skipFiles []string
skipDirs []string
patterns []string
policy []string
data []string
secretConfigPath string
key string
analyzerVersions analyzer.Versions
hookVersions map[string]int
skipFiles []string
skipDirs []string
patterns []string
policy []string
data []string
secretConfigPath string
detectionPriority types.DetectionPriority
}
tests := []struct {
name string
Expand Down Expand Up @@ -183,6 +185,23 @@ func TestCalcKey(t *testing.T) {
},
want: "sha256:363f70f4ee795f250873caea11c2fc94ef12945444327e7e2f8a99e3884695e0",
},
{
name: "detection priority",
args: args{
key: "sha256:5c534be56eca62e756ef2ef51523feda0f19cd7c15bb0c015e3d6e3ae090bf6e",
analyzerVersions: analyzer.Versions{
Analyzers: map[string]int{
"alpine": 1,
"debian": 1,
},
},
skipFiles: []string{"app/deployment.yaml"},
skipDirs: []string{"usr/java"},
policy: []string{"testdata/policy"},
detectionPriority: types.PriorityComprehensive,
},
want: "sha256:2f1c898271e84f4382cd48ae7533069cc3dc656c2d688ac108f5db1a0d9fd393",
},
{

name: "secret config",
Expand Down Expand Up @@ -237,7 +256,8 @@ func TestCalcKey(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
artifactOpt := artifact.Option{
FilePatterns: tt.args.patterns,
FilePatterns: tt.args.patterns,
DetectionPriority: tt.args.detectionPriority,

MisconfScannerOption: misconf.ScannerOption{
PolicyPaths: tt.args.policy,
Expand Down

0 comments on commit 1ce2e4b

Please sign in to comment.