github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/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/metasources/buildx/buildx/formats" 10 "github.com/metasources/buildx/buildx/formats/template" 11 ) 12 13 func TestAllFormatsExpressible(t *testing.T) { 14 commonAssertions := []traitAssertion{ 15 func(tb testing.TB, stdout, _ string, _ int) { 16 tb.Helper() 17 if len(stdout) < 1000 { 18 tb.Errorf("there may not be any report output (len=%d)", len(stdout)) 19 } 20 }, 21 assertSuccessfulReturnCode, 22 } 23 formatNames := formats.AllIDs() 24 require.NotEmpty(t, formatNames) 25 for _, o := range formatNames { 26 t.Run(fmt.Sprintf("format:%s", o), func(t *testing.T) { 27 args := []string{"dir:./test-fixtures/image-pkg-coverage", "-o", string(o)} 28 if o == template.ID { 29 args = append(args, "-t", "test-fixtures/csv.template") 30 } 31 32 cmd, stdout, stderr := runBuildx(t, nil, args...) 33 for _, traitFn := range commonAssertions { 34 traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode()) 35 } 36 logOutputOnFailure(t, cmd, stdout, stderr) 37 }) 38 } 39 }