github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/pkg/scanners/cloudformation/test/cf_scanning_test.go (about) 1 package test 2 3 import ( 4 "bytes" 5 "context" 6 "os" 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 12 "github.com/aquasecurity/defsec/pkg/scanners/options" 13 "github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation" 14 ) 15 16 func Test_basic_cloudformation_scanning(t *testing.T) { 17 cfScanner := cloudformation.New(options.ScannerWithEmbeddedPolicies(true), options.ScannerWithEmbeddedLibraries(true)) 18 19 results, err := cfScanner.ScanFS(context.TODO(), os.DirFS("./examples/bucket"), ".") 20 require.NoError(t, err) 21 22 assert.Greater(t, len(results.GetFailed()), 0) 23 } 24 25 func Test_cloudformation_scanning_has_expected_errors(t *testing.T) { 26 cfScanner := cloudformation.New(options.ScannerWithEmbeddedPolicies(true), options.ScannerWithEmbeddedLibraries(true)) 27 28 results, err := cfScanner.ScanFS(context.TODO(), os.DirFS("./examples/bucket"), ".") 29 require.NoError(t, err) 30 31 assert.Greater(t, len(results.GetFailed()), 0) 32 } 33 34 func Test_cloudformation_scanning_with_debug(t *testing.T) { 35 36 debugWriter := bytes.NewBufferString("") 37 38 scannerOptions := []options.ScannerOption{ 39 options.ScannerWithDebug(debugWriter), 40 } 41 cfScanner := cloudformation.New(scannerOptions...) 42 43 _, err := cfScanner.ScanFS(context.TODO(), os.DirFS("./examples/bucket"), ".") 44 require.NoError(t, err) 45 46 // check debug is as expected 47 assert.Greater(t, len(debugWriter.String()), 0) 48 }