2021-10-29 14:17:03 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-06-17 18:04:31 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-02-07 15:40:43 +00:00
|
|
|
"github.com/anchore/syft/syft/formats"
|
2022-09-13 15:20:52 +00:00
|
|
|
"github.com/anchore/syft/syft/formats/template"
|
2021-10-29 14:17:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAllFormatsExpressible(t *testing.T) {
|
|
|
|
commonAssertions := []traitAssertion{
|
|
|
|
func(tb testing.TB, stdout, _ string, _ int) {
|
|
|
|
tb.Helper()
|
|
|
|
if len(stdout) < 1000 {
|
|
|
|
tb.Errorf("there may not be any report output (len=%d)", len(stdout))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
assertSuccessfulReturnCode,
|
|
|
|
}
|
2023-02-07 15:40:43 +00:00
|
|
|
formatNames := formats.AllIDs()
|
|
|
|
require.NotEmpty(t, formatNames)
|
|
|
|
for _, o := range formatNames {
|
2021-10-29 14:17:03 +00:00
|
|
|
t.Run(fmt.Sprintf("format:%s", o), func(t *testing.T) {
|
2022-06-17 18:04:31 +00:00
|
|
|
args := []string{"dir:./test-fixtures/image-pkg-coverage", "-o", string(o)}
|
|
|
|
if o == template.ID {
|
|
|
|
args = append(args, "-t", "test-fixtures/csv.template")
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd, stdout, stderr := runSyft(t, nil, args...)
|
2021-10-29 14:17:03 +00:00
|
|
|
for _, traitFn := range commonAssertions {
|
|
|
|
traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode())
|
|
|
|
}
|
2023-04-14 18:33:36 +00:00
|
|
|
logOutputOnFailure(t, cmd, stdout, stderr)
|
2021-10-29 14:17:03 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|