github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/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/khulnasoft-lab/defsec/pkg/scanners/options"
    10  
    11  	"github.com/khulnasoft-lab/defsec/pkg/scanners/cloudformation"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  	"github.com/stretchr/testify/require"
    15  )
    16  
    17  func Test_basic_cloudformation_scanning(t *testing.T) {
    18  	cfScanner := cloudformation.New()
    19  
    20  	results, err := cfScanner.ScanFS(context.TODO(), os.DirFS("./examples/bucket"), ".")
    21  	require.NoError(t, err)
    22  
    23  	assert.Greater(t, len(results.GetFailed()), 0)
    24  }
    25  
    26  func Test_cloudformation_scanning_has_expected_errors(t *testing.T) {
    27  	cfScanner := cloudformation.New()
    28  
    29  	results, err := cfScanner.ScanFS(context.TODO(), os.DirFS("./examples/bucket"), ".")
    30  	require.NoError(t, err)
    31  
    32  	assert.Greater(t, len(results.GetFailed()), 0)
    33  }
    34  
    35  func Test_cloudformation_scanning_with_debug(t *testing.T) {
    36  
    37  	debugWriter := bytes.NewBufferString("")
    38  
    39  	scannerOptions := []options.ScannerOption{
    40  		options.ScannerWithDebug(debugWriter),
    41  	}
    42  	cfScanner := cloudformation.New(scannerOptions...)
    43  
    44  	_, err := cfScanner.ScanFS(context.TODO(), os.DirFS("./examples/bucket"), ".")
    45  	require.NoError(t, err)
    46  
    47  	// check debug is as expected
    48  	assert.Greater(t, len(debugWriter.String()), 0)
    49  }