update cataloger tests to use pkgtest utils (#1287)

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2022-10-25 11:20:02 -04:00
committed by GitHub
parent c7a653060d
commit bd5adbc9b3
6 changed files with 182 additions and 254 deletions
+7 -17
View File
@@ -1,22 +1,22 @@
package cpp
import (
"os"
"testing"
"github.com/go-test/deep"
"github.com/stretchr/testify/require"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
"github.com/anchore/syft/syft/source"
)
func TestParseConanlock(t *testing.T) {
fixture := "test-fixtures/conan.lock"
expected := []pkg.Package{
{
Name: "zlib",
Version: "1.2.12",
PURL: "pkg:conan/zlib@1.2.12",
Locations: source.NewLocationSet(source.NewLocation(fixture)),
Language: pkg.CPP,
Type: pkg.ConanPkg,
MetadataType: pkg.ConanLockMetadataType,
@@ -32,18 +32,8 @@ func TestParseConanlock(t *testing.T) {
},
}
fixture, err := os.Open("test-fixtures/conan.lock")
require.NoError(t, err)
// TODO: relationships are not under test
var expectedRelationships []artifact.Relationship
// TODO: no relationships are under test yet
actual, _, err := parseConanlock(nil, nil, source.LocationReadCloser{
Location: source.NewLocation(fixture.Name()),
ReadCloser: fixture,
})
require.NoError(t, err)
differences := deep.Equal(expected, actual)
if differences != nil {
t.Errorf("returned package list differed from expectation: %+v", differences)
}
pkgtest.TestGenericParser(t, fixture, parseConanlock, expected, expectedRelationships)
}