mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
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:
parent
c7a653060d
commit
bd5adbc9b3
@ -6,7 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-test/deep"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
@ -89,33 +90,21 @@ func TestDatabaseParser(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
file, err := os.Open("test-fixtures/files")
|
f, err := os.Open("test-fixtures/files")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Unable to read test-fixtures/file: ", err)
|
t.Cleanup(func() { require.NoError(t, f.Close()) })
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
err := file.Close()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal("closing file failed:", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
reader := bufio.NewReader(file)
|
reader := bufio.NewReader(f)
|
||||||
|
|
||||||
entry, err := parseAlpmDBEntry(reader)
|
entry, err := parseAlpmDBEntry(reader)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Unable to read file contents: ", err)
|
|
||||||
|
if diff := cmp.Diff(entry.Files, test.expected.Files); diff != "" {
|
||||||
|
t.Errorf("Files mismatch (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
if diff := deep.Equal(entry.Files, test.expected.Files); diff != nil {
|
if diff := cmp.Diff(entry.Backup, test.expected.Backup); diff != "" {
|
||||||
for _, d := range diff {
|
t.Errorf("Backup mismatch (-want +got):\n%s", diff)
|
||||||
t.Errorf("files diff: %+v", d)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if diff := deep.Equal(entry.Backup, test.expected.Backup); diff != nil {
|
|
||||||
for _, d := range diff {
|
|
||||||
t.Errorf("backup diff: %+v", d)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -167,28 +156,17 @@ func TestMtreeParse(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
file, err := os.Open("test-fixtures/mtree")
|
f, err := os.Open("test-fixtures/mtree")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Unable to read test-fixtures/mtree: ", err)
|
t.Cleanup(func() { require.NoError(t, f.Close()) })
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
err := file.Close()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal("closing file failed:", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
reader := bufio.NewReader(file)
|
reader := bufio.NewReader(f)
|
||||||
|
|
||||||
entry, err := parseMtree(reader)
|
entry, err := parseMtree(reader)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Unable to read file contents: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if diff := deep.Equal(entry, test.expected); diff != nil {
|
if diff := cmp.Diff(entry, test.expected); diff != "" {
|
||||||
for _, d := range diff {
|
t.Errorf("Files mismatch (-want +got):\n%s", diff)
|
||||||
t.Errorf("files diff: %+v", d)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,14 +5,16 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-test/deep"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/linux"
|
"github.com/anchore/syft/syft/linux"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/generic"
|
"github.com/anchore/syft/syft/pkg/cataloger/generic"
|
||||||
|
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
|
||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,28 +59,17 @@ func TestExtraFileAttributes(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
file, err := os.Open("test-fixtures/extra-file-attributes")
|
f, err := os.Open("test-fixtures/extra-file-attributes")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Unable to read test-fixtures/extra-file-attributes: ", err)
|
t.Cleanup(func() { require.NoError(t, f.Close()) })
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
err := file.Close()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal("closing file failed:", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
reader := bufio.NewReader(file)
|
reader := bufio.NewReader(f)
|
||||||
|
|
||||||
entry, err := parseApkDBEntry(reader)
|
entry, err := parseApkDBEntry(reader)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("Unable to read file contents: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if diff := deep.Equal(entry.Files, test.expected.Files); diff != nil {
|
if diff := cmp.Diff(entry.Files, test.expected.Files); diff != "" {
|
||||||
for _, d := range diff {
|
t.Errorf("Files mismatch (-want +got):\n%s", diff)
|
||||||
t.Errorf("diff: %+v", d)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -623,135 +614,131 @@ func TestSinglePackageDetails(t *testing.T) {
|
|||||||
t.Run(test.fixture, func(t *testing.T) {
|
t.Run(test.fixture, func(t *testing.T) {
|
||||||
f, err := os.Open(test.fixture)
|
f, err := os.Open(test.fixture)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Cleanup(func() { f.Close() })
|
t.Cleanup(func() { require.NoError(t, f.Close()) })
|
||||||
|
|
||||||
reader := bufio.NewReader(f)
|
reader := bufio.NewReader(f)
|
||||||
|
|
||||||
entry, err := parseApkDBEntry(reader)
|
entry, err := parseApkDBEntry(reader)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, entry)
|
||||||
|
|
||||||
if diff := deep.Equal(*entry, test.expected); diff != nil {
|
if diff := cmp.Diff(*entry, test.expected); diff != "" {
|
||||||
for _, d := range diff {
|
t.Errorf("Entry mismatch (-want +got):\n%s", diff)
|
||||||
t.Errorf("diff: %+v", d)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiplePackages(t *testing.T) {
|
func TestMultiplePackages(t *testing.T) {
|
||||||
tests := []struct {
|
|
||||||
fixture string
|
fixture := "test-fixtures/multiple"
|
||||||
expected []pkg.Package
|
fixtureLocationSet := source.NewLocationSet(source.NewLocation(fixture))
|
||||||
}{
|
expected := []pkg.Package{
|
||||||
{
|
{
|
||||||
fixture: "test-fixtures/multiple",
|
Name: "libc-utils",
|
||||||
expected: []pkg.Package{
|
Version: "0.7.2-r0",
|
||||||
{
|
Licenses: []string{"BSD"},
|
||||||
Name: "libc-utils",
|
Type: pkg.ApkPkg,
|
||||||
Version: "0.7.2-r0",
|
PURL: "pkg:alpine/libc-utils@0.7.2-r0?arch=x86_64&upstream=libc-dev&distro=alpine-3.12",
|
||||||
Licenses: []string{"BSD"},
|
Locations: fixtureLocationSet,
|
||||||
Type: pkg.ApkPkg,
|
MetadataType: pkg.ApkMetadataType,
|
||||||
PURL: "pkg:alpine/libc-utils@0.7.2-r0?arch=x86_64&upstream=libc-dev&distro=alpine",
|
Metadata: pkg.ApkMetadata{
|
||||||
MetadataType: pkg.ApkMetadataType,
|
Package: "libc-utils",
|
||||||
Metadata: pkg.ApkMetadata{
|
OriginPackage: "libc-dev",
|
||||||
Package: "libc-utils",
|
Maintainer: "Natanael Copa <ncopa@alpinelinux.org>",
|
||||||
OriginPackage: "libc-dev",
|
Version: "0.7.2-r0",
|
||||||
Maintainer: "Natanael Copa <ncopa@alpinelinux.org>",
|
License: "BSD",
|
||||||
Version: "0.7.2-r0",
|
Architecture: "x86_64",
|
||||||
License: "BSD",
|
URL: "http://alpinelinux.org",
|
||||||
Architecture: "x86_64",
|
Description: "Meta package to pull in correct libc",
|
||||||
URL: "http://alpinelinux.org",
|
Size: 1175,
|
||||||
Description: "Meta package to pull in correct libc",
|
InstalledSize: 4096,
|
||||||
Size: 1175,
|
PullChecksum: "Q1p78yvTLG094tHE1+dToJGbmYzQE=",
|
||||||
InstalledSize: 4096,
|
GitCommitOfAport: "97b1c2842faa3bfa30f5811ffbf16d5ff9f1a479",
|
||||||
PullChecksum: "Q1p78yvTLG094tHE1+dToJGbmYzQE=",
|
PullDependencies: "musl-utils",
|
||||||
GitCommitOfAport: "97b1c2842faa3bfa30f5811ffbf16d5ff9f1a479",
|
Files: []pkg.ApkFileRecord{},
|
||||||
PullDependencies: "musl-utils",
|
},
|
||||||
Files: []pkg.ApkFileRecord{},
|
},
|
||||||
|
{
|
||||||
|
Name: "musl-utils",
|
||||||
|
Version: "1.1.24-r2",
|
||||||
|
Licenses: []string{"MIT", "BSD", "GPL2+"},
|
||||||
|
Type: pkg.ApkPkg,
|
||||||
|
PURL: "pkg:alpine/musl-utils@1.1.24-r2?arch=x86_64&upstream=musl&distro=alpine-3.12",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
|
MetadataType: pkg.ApkMetadataType,
|
||||||
|
Metadata: pkg.ApkMetadata{
|
||||||
|
Package: "musl-utils",
|
||||||
|
OriginPackage: "musl",
|
||||||
|
Version: "1.1.24-r2",
|
||||||
|
Description: "the musl c library (libc) implementation",
|
||||||
|
Maintainer: "Timo Teräs <timo.teras@iki.fi>",
|
||||||
|
License: "MIT BSD GPL2+",
|
||||||
|
Architecture: "x86_64",
|
||||||
|
URL: "https://musl.libc.org/",
|
||||||
|
Size: 37944,
|
||||||
|
InstalledSize: 151552,
|
||||||
|
PullDependencies: "scanelf so:libc.musl-x86_64.so.1",
|
||||||
|
PullChecksum: "Q1bTtF5526tETKfL+lnigzIDvm+2o=",
|
||||||
|
GitCommitOfAport: "4024cc3b29ad4c65544ad068b8f59172b5494306",
|
||||||
|
Files: []pkg.ApkFileRecord{
|
||||||
|
{
|
||||||
|
Path: "/sbin",
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
Path: "/sbin/ldconfig",
|
||||||
Name: "musl-utils",
|
OwnerUID: "0",
|
||||||
Version: "1.1.24-r2",
|
OwnerGID: "0",
|
||||||
Licenses: []string{"MIT", "BSD", "GPL2+"},
|
Permissions: "755",
|
||||||
Type: pkg.ApkPkg,
|
Digest: &file.Digest{
|
||||||
PURL: "pkg:alpine/musl-utils@1.1.24-r2?arch=x86_64&upstream=musl&distro=alpine",
|
Algorithm: "'Q1'+base64(sha1)",
|
||||||
MetadataType: pkg.ApkMetadataType,
|
Value: "Q1Kja2+POZKxEkUOZqwSjC6kmaED4=",
|
||||||
Metadata: pkg.ApkMetadata{
|
},
|
||||||
Package: "musl-utils",
|
},
|
||||||
OriginPackage: "musl",
|
{
|
||||||
Version: "1.1.24-r2",
|
Path: "/usr",
|
||||||
Description: "the musl c library (libc) implementation",
|
},
|
||||||
Maintainer: "Timo Teräs <timo.teras@iki.fi>",
|
{
|
||||||
License: "MIT BSD GPL2+",
|
Path: "/usr/bin",
|
||||||
Architecture: "x86_64",
|
},
|
||||||
URL: "https://musl.libc.org/",
|
{
|
||||||
Size: 37944,
|
Path: "/usr/bin/iconv",
|
||||||
InstalledSize: 151552,
|
OwnerUID: "0",
|
||||||
PullDependencies: "scanelf so:libc.musl-x86_64.so.1",
|
OwnerGID: "0",
|
||||||
PullChecksum: "Q1bTtF5526tETKfL+lnigzIDvm+2o=",
|
Permissions: "755",
|
||||||
GitCommitOfAport: "4024cc3b29ad4c65544ad068b8f59172b5494306",
|
Digest: &file.Digest{
|
||||||
Files: []pkg.ApkFileRecord{
|
Algorithm: "'Q1'+base64(sha1)",
|
||||||
{
|
Value: "Q1CVmFbdY+Hv6/jAHl1gec2Kbx1EY=",
|
||||||
Path: "/sbin",
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Path: "/sbin/ldconfig",
|
Path: "/usr/bin/ldd",
|
||||||
OwnerUID: "0",
|
OwnerUID: "0",
|
||||||
OwnerGID: "0",
|
OwnerGID: "0",
|
||||||
Permissions: "755",
|
Permissions: "755",
|
||||||
Digest: &file.Digest{
|
Digest: &file.Digest{
|
||||||
Algorithm: "'Q1'+base64(sha1)",
|
Algorithm: "'Q1'+base64(sha1)",
|
||||||
Value: "Q1Kja2+POZKxEkUOZqwSjC6kmaED4=",
|
Value: "Q1yFAhGggmL7ERgbIA7KQxyTzf3ks=",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Path: "/usr",
|
Path: "/usr/bin/getconf",
|
||||||
},
|
OwnerUID: "0",
|
||||||
{
|
OwnerGID: "0",
|
||||||
Path: "/usr/bin",
|
Permissions: "755",
|
||||||
},
|
Digest: &file.Digest{
|
||||||
{
|
Algorithm: "'Q1'+base64(sha1)",
|
||||||
Path: "/usr/bin/iconv",
|
Value: "Q1dAdYK8M/INibRQF5B3Rw7cmNDDA=",
|
||||||
OwnerUID: "0",
|
},
|
||||||
OwnerGID: "0",
|
},
|
||||||
Permissions: "755",
|
{
|
||||||
Digest: &file.Digest{
|
Path: "/usr/bin/getent",
|
||||||
Algorithm: "'Q1'+base64(sha1)",
|
OwnerUID: "0",
|
||||||
Value: "Q1CVmFbdY+Hv6/jAHl1gec2Kbx1EY=",
|
OwnerGID: "0",
|
||||||
},
|
Permissions: "755",
|
||||||
},
|
Digest: &file.Digest{
|
||||||
{
|
Algorithm: "'Q1'+base64(sha1)",
|
||||||
Path: "/usr/bin/ldd",
|
Value: "Q1eR2Dz/WylabgbWMTkd2+hGmEya4=",
|
||||||
OwnerUID: "0",
|
|
||||||
OwnerGID: "0",
|
|
||||||
Permissions: "755",
|
|
||||||
Digest: &file.Digest{
|
|
||||||
Algorithm: "'Q1'+base64(sha1)",
|
|
||||||
Value: "Q1yFAhGggmL7ERgbIA7KQxyTzf3ks=",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Path: "/usr/bin/getconf",
|
|
||||||
OwnerUID: "0",
|
|
||||||
OwnerGID: "0",
|
|
||||||
Permissions: "755",
|
|
||||||
Digest: &file.Digest{
|
|
||||||
Algorithm: "'Q1'+base64(sha1)",
|
|
||||||
Value: "Q1dAdYK8M/INibRQF5B3Rw7cmNDDA=",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Path: "/usr/bin/getent",
|
|
||||||
OwnerUID: "0",
|
|
||||||
OwnerGID: "0",
|
|
||||||
Permissions: "755",
|
|
||||||
Digest: &file.Digest{
|
|
||||||
Algorithm: "'Q1'+base64(sha1)",
|
|
||||||
Value: "Q1eR2Dz/WylabgbWMTkd2+hGmEya4=",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -759,37 +746,16 @@ func TestMultiplePackages(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
// TODO: relationships are not under test
|
||||||
t.Run(test.fixture, func(t *testing.T) {
|
var expectedRelationships []artifact.Relationship
|
||||||
f, err := os.Open(test.fixture)
|
|
||||||
require.NoError(t, err)
|
|
||||||
t.Cleanup(func() { f.Close() })
|
|
||||||
|
|
||||||
// TODO: no relationships are under test yet
|
env := generic.Environment{LinuxRelease: &linux.Release{
|
||||||
pkgs, _, err := parseApkDB(nil, &generic.Environment{
|
ID: "alpine",
|
||||||
LinuxRelease: &linux.Release{
|
VersionID: "3.12",
|
||||||
ID: "alpine",
|
}}
|
||||||
},
|
|
||||||
}, source.LocationReadCloser{
|
|
||||||
Location: source.NewLocation(f.Name()),
|
|
||||||
ReadCloser: f,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
if len(pkgs) != 2 {
|
pkgtest.TestGenericParserWithEnv(t, fixture, parseApkDB, &env, expected, expectedRelationships)
|
||||||
t.Fatalf("unexpected number of entries: %d", len(pkgs))
|
|
||||||
}
|
|
||||||
|
|
||||||
for idx, entry := range pkgs {
|
|
||||||
if diff := deep.Equal(entry, test.expected[idx]); diff != nil {
|
|
||||||
for _, d := range diff {
|
|
||||||
t.Errorf("diff: %+v", d)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_processChecksum(t *testing.T) {
|
func Test_processChecksum(t *testing.T) {
|
||||||
|
|||||||
@ -1,22 +1,23 @@
|
|||||||
package cpp
|
package cpp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-test/deep"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
|
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
|
||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseConanfile(t *testing.T) {
|
func TestParseConanfile(t *testing.T) {
|
||||||
|
fixture := "test-fixtures/conanfile.txt"
|
||||||
|
fixtureLocationSet := source.NewLocationSet(source.NewLocation(fixture))
|
||||||
expected := []pkg.Package{
|
expected := []pkg.Package{
|
||||||
{
|
{
|
||||||
Name: "catch2",
|
Name: "catch2",
|
||||||
Version: "2.13.8",
|
Version: "2.13.8",
|
||||||
PURL: "pkg:conan/catch2@2.13.8",
|
PURL: "pkg:conan/catch2@2.13.8",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.CPP,
|
Language: pkg.CPP,
|
||||||
Type: pkg.ConanPkg,
|
Type: pkg.ConanPkg,
|
||||||
MetadataType: pkg.ConanMetadataType,
|
MetadataType: pkg.ConanMetadataType,
|
||||||
@ -28,6 +29,7 @@ func TestParseConanfile(t *testing.T) {
|
|||||||
Name: "docopt.cpp",
|
Name: "docopt.cpp",
|
||||||
Version: "0.6.3",
|
Version: "0.6.3",
|
||||||
PURL: "pkg:conan/docopt.cpp@0.6.3",
|
PURL: "pkg:conan/docopt.cpp@0.6.3",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.CPP,
|
Language: pkg.CPP,
|
||||||
Type: pkg.ConanPkg,
|
Type: pkg.ConanPkg,
|
||||||
MetadataType: pkg.ConanMetadataType,
|
MetadataType: pkg.ConanMetadataType,
|
||||||
@ -39,6 +41,7 @@ func TestParseConanfile(t *testing.T) {
|
|||||||
Name: "fmt",
|
Name: "fmt",
|
||||||
Version: "8.1.1",
|
Version: "8.1.1",
|
||||||
PURL: "pkg:conan/fmt@8.1.1",
|
PURL: "pkg:conan/fmt@8.1.1",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.CPP,
|
Language: pkg.CPP,
|
||||||
Type: pkg.ConanPkg,
|
Type: pkg.ConanPkg,
|
||||||
MetadataType: pkg.ConanMetadataType,
|
MetadataType: pkg.ConanMetadataType,
|
||||||
@ -50,6 +53,7 @@ func TestParseConanfile(t *testing.T) {
|
|||||||
Name: "spdlog",
|
Name: "spdlog",
|
||||||
Version: "1.9.2",
|
Version: "1.9.2",
|
||||||
PURL: "pkg:conan/spdlog@1.9.2",
|
PURL: "pkg:conan/spdlog@1.9.2",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.CPP,
|
Language: pkg.CPP,
|
||||||
Type: pkg.ConanPkg,
|
Type: pkg.ConanPkg,
|
||||||
MetadataType: pkg.ConanMetadataType,
|
MetadataType: pkg.ConanMetadataType,
|
||||||
@ -61,6 +65,7 @@ func TestParseConanfile(t *testing.T) {
|
|||||||
Name: "sdl",
|
Name: "sdl",
|
||||||
Version: "2.0.20",
|
Version: "2.0.20",
|
||||||
PURL: "pkg:conan/sdl@2.0.20",
|
PURL: "pkg:conan/sdl@2.0.20",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.CPP,
|
Language: pkg.CPP,
|
||||||
Type: pkg.ConanPkg,
|
Type: pkg.ConanPkg,
|
||||||
MetadataType: pkg.ConanMetadataType,
|
MetadataType: pkg.ConanMetadataType,
|
||||||
@ -72,6 +77,7 @@ func TestParseConanfile(t *testing.T) {
|
|||||||
Name: "fltk",
|
Name: "fltk",
|
||||||
Version: "1.3.8",
|
Version: "1.3.8",
|
||||||
PURL: "pkg:conan/fltk@1.3.8",
|
PURL: "pkg:conan/fltk@1.3.8",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.CPP,
|
Language: pkg.CPP,
|
||||||
Type: pkg.ConanPkg,
|
Type: pkg.ConanPkg,
|
||||||
MetadataType: pkg.ConanMetadataType,
|
MetadataType: pkg.ConanMetadataType,
|
||||||
@ -81,18 +87,8 @@ func TestParseConanfile(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fixture, err := os.Open("test-fixtures/conanfile.txt")
|
// TODO: relationships are not under test
|
||||||
require.NoError(t, err)
|
var expectedRelationships []artifact.Relationship
|
||||||
|
|
||||||
// TODO: no relationships are under test yet
|
pkgtest.TestGenericParser(t, fixture, parseConanfile, expected, expectedRelationships)
|
||||||
actual, _, err := parseConanfile(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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,22 +1,22 @@
|
|||||||
package cpp
|
package cpp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-test/deep"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
|
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
|
||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseConanlock(t *testing.T) {
|
func TestParseConanlock(t *testing.T) {
|
||||||
|
fixture := "test-fixtures/conan.lock"
|
||||||
expected := []pkg.Package{
|
expected := []pkg.Package{
|
||||||
{
|
{
|
||||||
Name: "zlib",
|
Name: "zlib",
|
||||||
Version: "1.2.12",
|
Version: "1.2.12",
|
||||||
PURL: "pkg:conan/zlib@1.2.12",
|
PURL: "pkg:conan/zlib@1.2.12",
|
||||||
|
Locations: source.NewLocationSet(source.NewLocation(fixture)),
|
||||||
Language: pkg.CPP,
|
Language: pkg.CPP,
|
||||||
Type: pkg.ConanPkg,
|
Type: pkg.ConanPkg,
|
||||||
MetadataType: pkg.ConanLockMetadataType,
|
MetadataType: pkg.ConanLockMetadataType,
|
||||||
@ -32,18 +32,8 @@ func TestParseConanlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fixture, err := os.Open("test-fixtures/conan.lock")
|
// TODO: relationships are not under test
|
||||||
require.NoError(t, err)
|
var expectedRelationships []artifact.Relationship
|
||||||
|
|
||||||
// TODO: no relationships are under test yet
|
pkgtest.TestGenericParser(t, fixture, parseConanlock, expected, expectedRelationships)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,22 +1,23 @@
|
|||||||
package dart
|
package dart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-test/deep"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
|
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
|
||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParsePubspecLock(t *testing.T) {
|
func TestParsePubspecLock(t *testing.T) {
|
||||||
|
fixture := "test-fixtures/pubspec.lock"
|
||||||
|
fixtureLocationSet := source.NewLocationSet(source.NewLocation(fixture))
|
||||||
expected := []pkg.Package{
|
expected := []pkg.Package{
|
||||||
{
|
{
|
||||||
Name: "ale",
|
Name: "ale",
|
||||||
Version: "3.3.0",
|
Version: "3.3.0",
|
||||||
PURL: "pkg:pub/ale@3.3.0?hosted_url=pub.hosted.org",
|
PURL: "pkg:pub/ale@3.3.0?hosted_url=pub.hosted.org",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.Dart,
|
Language: pkg.Dart,
|
||||||
Type: pkg.DartPubPkg,
|
Type: pkg.DartPubPkg,
|
||||||
MetadataType: pkg.DartPubMetadataType,
|
MetadataType: pkg.DartPubMetadataType,
|
||||||
@ -30,6 +31,7 @@ func TestParsePubspecLock(t *testing.T) {
|
|||||||
Name: "analyzer",
|
Name: "analyzer",
|
||||||
Version: "0.40.7",
|
Version: "0.40.7",
|
||||||
PURL: "pkg:pub/analyzer@0.40.7",
|
PURL: "pkg:pub/analyzer@0.40.7",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.Dart,
|
Language: pkg.Dart,
|
||||||
Type: pkg.DartPubPkg,
|
Type: pkg.DartPubPkg,
|
||||||
MetadataType: pkg.DartPubMetadataType,
|
MetadataType: pkg.DartPubMetadataType,
|
||||||
@ -42,6 +44,7 @@ func TestParsePubspecLock(t *testing.T) {
|
|||||||
Name: "ansicolor",
|
Name: "ansicolor",
|
||||||
Version: "1.1.1",
|
Version: "1.1.1",
|
||||||
PURL: "pkg:pub/ansicolor@1.1.1",
|
PURL: "pkg:pub/ansicolor@1.1.1",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.Dart,
|
Language: pkg.Dart,
|
||||||
Type: pkg.DartPubPkg,
|
Type: pkg.DartPubPkg,
|
||||||
MetadataType: pkg.DartPubMetadataType,
|
MetadataType: pkg.DartPubMetadataType,
|
||||||
@ -54,6 +57,7 @@ func TestParsePubspecLock(t *testing.T) {
|
|||||||
Name: "archive",
|
Name: "archive",
|
||||||
Version: "2.0.13",
|
Version: "2.0.13",
|
||||||
PURL: "pkg:pub/archive@2.0.13",
|
PURL: "pkg:pub/archive@2.0.13",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.Dart,
|
Language: pkg.Dart,
|
||||||
Type: pkg.DartPubPkg,
|
Type: pkg.DartPubPkg,
|
||||||
MetadataType: pkg.DartPubMetadataType,
|
MetadataType: pkg.DartPubMetadataType,
|
||||||
@ -66,6 +70,7 @@ func TestParsePubspecLock(t *testing.T) {
|
|||||||
Name: "args",
|
Name: "args",
|
||||||
Version: "1.6.0",
|
Version: "1.6.0",
|
||||||
PURL: "pkg:pub/args@1.6.0",
|
PURL: "pkg:pub/args@1.6.0",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.Dart,
|
Language: pkg.Dart,
|
||||||
Type: pkg.DartPubPkg,
|
Type: pkg.DartPubPkg,
|
||||||
MetadataType: pkg.DartPubMetadataType,
|
MetadataType: pkg.DartPubMetadataType,
|
||||||
@ -78,6 +83,7 @@ func TestParsePubspecLock(t *testing.T) {
|
|||||||
Name: "key_binder",
|
Name: "key_binder",
|
||||||
Version: "1.11.20",
|
Version: "1.11.20",
|
||||||
PURL: "pkg:pub/key_binder@1.11.20?vcs_url=git%40github.com:Workiva/key_binder.git%403f7b3a6350e73c7dcac45301c0e18fbd42af02f7",
|
PURL: "pkg:pub/key_binder@1.11.20?vcs_url=git%40github.com:Workiva/key_binder.git%403f7b3a6350e73c7dcac45301c0e18fbd42af02f7",
|
||||||
|
Locations: fixtureLocationSet,
|
||||||
Language: pkg.Dart,
|
Language: pkg.Dart,
|
||||||
Type: pkg.DartPubPkg,
|
Type: pkg.DartPubPkg,
|
||||||
MetadataType: pkg.DartPubMetadataType,
|
MetadataType: pkg.DartPubMetadataType,
|
||||||
@ -89,18 +95,8 @@ func TestParsePubspecLock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fixture, err := os.Open("test-fixtures/pubspec.lock")
|
// TODO: relationships are not under test
|
||||||
require.NoError(t, err)
|
var expectedRelationships []artifact.Relationship
|
||||||
|
|
||||||
// TODO: no relationships are under test yet
|
pkgtest.TestGenericParser(t, fixture, parsePubspecLock, expected, expectedRelationships)
|
||||||
actual, _, err := parsePubspecLock(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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,10 +14,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGenericParser(t *testing.T, fixturePath string, parser generic.Parser, expectedPkgs []pkg.Package, expectedRelationships []artifact.Relationship) {
|
func TestGenericParser(t *testing.T, fixturePath string, parser generic.Parser, expectedPkgs []pkg.Package, expectedRelationships []artifact.Relationship) {
|
||||||
|
t.Helper()
|
||||||
TestGenericParserWithEnv(t, fixturePath, parser, nil, expectedPkgs, expectedRelationships)
|
TestGenericParserWithEnv(t, fixturePath, parser, nil, expectedPkgs, expectedRelationships)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenericParserWithEnv(t *testing.T, fixturePath string, parser generic.Parser, env *generic.Environment, expectedPkgs []pkg.Package, expectedRelationships []artifact.Relationship) {
|
func TestGenericParserWithEnv(t *testing.T, fixturePath string, parser generic.Parser, env *generic.Environment, expectedPkgs []pkg.Package, expectedRelationships []artifact.Relationship) {
|
||||||
|
t.Helper()
|
||||||
fixture, err := os.Open(fixturePath)
|
fixture, err := os.Open(fixturePath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user