-
Notifications
You must be signed in to change notification settings - Fork 527
/
all_formats_expressible_test.go
78 lines (70 loc) · 1.93 KB
/
all_formats_expressible_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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)
})
}
}
func Test_formatVersionsExpressible(t *testing.T) {
tests := []struct {
format string
assertion traitAssertion
}{
{
format: "spdx@2.1",
assertion: assertInOutput("SPDXVersion: SPDX-2.1"),
},
{
format: "spdx@2.2",
assertion: assertInOutput("SPDXVersion: SPDX-2.2"),
},
{
format: "spdx@2.3",
assertion: assertInOutput("SPDXVersion: SPDX-2.3"),
},
{
format: "spdx-json@2.2",
assertion: assertInOutput(`"spdxVersion":"SPDX-2.2"`),
},
{
format: "spdx-json@2.3",
assertion: assertInOutput(`"spdxVersion":"SPDX-2.3"`),
},
}
for _, test := range tests {
t.Run(test.format, func(t *testing.T) {
args := []string{"dir:./test-fixtures/image-pkg-coverage", "-o", test.format}
cmd, stdout, stderr := runSyft(t, nil, args...)
test.assertion(t, stdout, stderr, cmd.ProcessState.ExitCode())
logOutputOnFailure(t, cmd, stdout, stderr)
})
}
}