github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/test/cli/all_formats_expressible_test.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/nextlinux/gosbom/gosbom/formats" 8 "github.com/nextlinux/gosbom/gosbom/formats/template" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestAllFormatsExpressible(t *testing.T) { 13 commonAssertions := []traitAssertion{ 14 func(tb testing.TB, stdout, _ string, _ int) { 15 tb.Helper() 16 if len(stdout) < 1000 { 17 tb.Errorf("there may not be any report output (len=%d)", len(stdout)) 18 } 19 }, 20 assertSuccessfulReturnCode, 21 } 22 formatNames := formats.AllIDs() 23 require.NotEmpty(t, formatNames) 24 for _, o := range formatNames { 25 t.Run(fmt.Sprintf("format:%s", o), func(t *testing.T) { 26 args := []string{"dir:./test-fixtures/image-pkg-coverage", "-o", string(o)} 27 if o == template.ID { 28 args = append(args, "-t", "test-fixtures/csv.template") 29 } 30 31 cmd, stdout, stderr := runGosbom(t, nil, args...) 32 for _, traitFn := range commonAssertions { 33 traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode()) 34 } 35 logOutputOnFailure(t, cmd, stdout, stderr) 36 }) 37 } 38 }