syft/internal/formats/formats_test.go
Alex Goodman bcdebcadaf
add internal.formats helper functions + identify tests
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
2021-10-10 18:32:02 -07:00

40 lines
747 B
Go

package formats
import (
"io"
"os"
"testing"
"github.com/anchore/syft/syft/format"
"github.com/stretchr/testify/assert"
)
func TestIdentify(t *testing.T) {
tests := []struct {
fixture string
expected format.Option
}{
{
fixture: "test-fixtures/alpine-syft.json",
expected: format.JSONOption,
},
{
fixture: "test-fixtures/alpine-syft-spdx.json",
expected: format.SPDXJSONOption,
},
}
for _, test := range tests {
t.Run(test.fixture, func(t *testing.T) {
f, err := os.Open(test.fixture)
assert.NoError(t, err)
by, err := io.ReadAll(f)
assert.NoError(t, err)
frmt, err := Identify(by)
assert.NoError(t, err)
assert.NotNil(t, frmt)
assert.Equal(t, test.expected, frmt.Option)
})
}
}