mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
* internalize majority of cmd package and migrate integration tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add internal api encoder Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * create internal representation of all formats Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * export capability to get default encoders Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * restore test fixtures Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/anchore/syft/syft/format"
|
|
"github.com/anchore/syft/syft/format/template"
|
|
)
|
|
|
|
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,
|
|
}
|
|
|
|
encs := format.NewEncoderCollection(format.Encoders()...)
|
|
formatIDs := encs.IDs()
|
|
require.NotEmpty(t, formatIDs)
|
|
for _, o := range formatIDs {
|
|
t.Run(fmt.Sprintf("format:%s", o), func(t *testing.T) {
|
|
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...)
|
|
for _, traitFn := range commonAssertions {
|
|
traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode())
|
|
}
|
|
logOutputOnFailure(t, cmd, stdout, stderr)
|
|
})
|
|
}
|
|
}
|