github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/test/cli/all_formats_expressible_test.go (about)

     1  package cli
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/anchore/syft/cmd/syft/cli/options"
    10  	"github.com/anchore/syft/syft/format"
    11  	"github.com/anchore/syft/syft/format/template"
    12  )
    13  
    14  func TestAllFormatsExpressible(t *testing.T) {
    15  	commonAssertions := []traitAssertion{
    16  		func(tb testing.TB, stdout, _ string, _ int) {
    17  			tb.Helper()
    18  			if len(stdout) < 1000 {
    19  				tb.Errorf("there may not be any report output (len=%d)", len(stdout))
    20  			}
    21  		},
    22  		assertSuccessfulReturnCode,
    23  	}
    24  
    25  	opts := options.DefaultOutput()
    26  	require.NoError(t, opts.PostLoad())
    27  	encoders, err := opts.Encoders()
    28  	require.NoError(t, err)
    29  
    30  	encs := format.NewEncoderCollection(encoders...)
    31  	formatIDs := encs.IDs()
    32  	require.NotEmpty(t, formatIDs)
    33  	for _, o := range formatIDs {
    34  		t.Run(fmt.Sprintf("format:%s", o), func(t *testing.T) {
    35  			args := []string{"dir:./test-fixtures/image-pkg-coverage", "-o", string(o)}
    36  			if o == template.ID {
    37  				args = append(args, "-t", "test-fixtures/csv.template")
    38  			}
    39  
    40  			cmd, stdout, stderr := runSyft(t, nil, args...)
    41  			for _, traitFn := range commonAssertions {
    42  				traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode())
    43  			}
    44  			logOutputOnFailure(t, cmd, stdout, stderr)
    45  		})
    46  	}
    47  }