mirror of
https://github.com/aquasecurity/trivy.git
synced 2026-01-31 13:53:14 +08:00
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io> Co-authored-by: knqyf263 <knqyf263@gmail.com>
25 lines
589 B
Go
25 lines
589 B
Go
package testutil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/aquasecurity/trivy/internal/testutil"
|
|
"github.com/aquasecurity/trivy/pkg/iac/scanners/cloudformation/parser"
|
|
)
|
|
|
|
type adaptFn[T any] func(fctx parser.FileContext) T
|
|
|
|
func AdaptAndCompare[T any](t *testing.T, source string, expected any, fn adaptFn[T]) {
|
|
fsys := testutil.CreateFS(map[string]string{
|
|
"main.yaml": source,
|
|
})
|
|
|
|
fctx, err := parser.New().ParseFile(t.Context(), fsys, "main.yaml")
|
|
require.NoError(t, err)
|
|
|
|
adapted := fn(*fctx)
|
|
testutil.AssertDefsecEqual(t, expected, adapted)
|
|
}
|