syft/test/cli/all_formats_expressible_test.go
Alex Goodman e0e1c4ba0a
Internalize majority of cmd package (#2533)
* 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>
2024-01-24 13:29:51 -05:00

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)
})
}
}