mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-12 07:40:48 -08:00
test: replace Go checks with Rego (#7867)
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/liamg/memoryfs"
|
||||
"github.com/samber/lo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -36,6 +37,16 @@ func AssertRuleNotFound(t *testing.T, ruleID string, results scan.Results, messa
|
||||
assert.False(t, found, append([]any{message}, args...)...)
|
||||
}
|
||||
|
||||
func AssertRuleNotFailed(t *testing.T, ruleID string, results scan.Results, message string, args ...any) {
|
||||
failedExists := ruleIDInResults(ruleID, results.GetFailed())
|
||||
assert.False(t, failedExists, append([]any{message}, args...)...)
|
||||
passedResults := lo.Filter(results, func(res scan.Result, _ int) bool {
|
||||
return res.Status() == scan.StatusPassed || res.Status() == scan.StatusIgnored
|
||||
})
|
||||
passedExists := ruleIDInResults(ruleID, passedResults)
|
||||
assert.True(t, passedExists, append([]any{message}, args...)...)
|
||||
}
|
||||
|
||||
func ruleIDInResults(ruleID string, results scan.Results) bool {
|
||||
for _, res := range results {
|
||||
if res.Rule().LongID() == ruleID {
|
||||
|
||||
Reference in New Issue
Block a user