github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/pkg/cataloger/gentoo/cataloger_test.go (about) 1 package gentoo 2 3 import ( 4 "testing" 5 6 "github.com/anchore/syft/syft/artifact" 7 "github.com/anchore/syft/syft/file" 8 "github.com/anchore/syft/syft/pkg" 9 "github.com/lineaje-labs/syft/syft/pkg/cataloger/internal/pkgtest" 10 ) 11 12 func TestPortageCataloger(t *testing.T) { 13 expectedLicenseLocation := file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/LICENSE") 14 expectedPkgs := []pkg.Package{ 15 { 16 Name: "app-containers/skopeo", 17 Version: "1.5.1", 18 FoundBy: "portage-cataloger", 19 PURL: "pkg:ebuild/app-containers/skopeo@1.5.1", 20 Locations: file.NewLocationSet( 21 file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/CONTENTS"), 22 file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/SIZE"), 23 expectedLicenseLocation, 24 ), 25 Licenses: pkg.NewLicenseSet(pkg.NewLicensesFromLocation(expectedLicenseLocation, "Apache-2.0", "BSD", "BSD-2", "CC-BY-SA-4.0", "ISC", "MIT")...), 26 Type: pkg.PortagePkg, 27 Metadata: pkg.PortageEntry{ 28 InstalledSize: 27937835, 29 Files: []pkg.PortageFileRecord{ 30 { 31 Path: "/usr/bin/skopeo", 32 Digest: &file.Digest{ 33 Algorithm: "md5", 34 Value: "376c02bd3b22804df8fdfdc895e7dbfb", 35 }, 36 }, 37 { 38 Path: "/etc/containers/policy.json", 39 Digest: &file.Digest{ 40 Algorithm: "md5", 41 Value: "c01eb6950f03419e09d4fc88cb42ff6f", 42 }, 43 }, 44 { 45 Path: "/etc/containers/registries.d/default.yaml", 46 Digest: &file.Digest{ 47 Algorithm: "md5", 48 Value: "e6e66cd3c24623e0667f26542e0e08f6", 49 }, 50 }, 51 { 52 Path: "/var/lib/atomic/sigstore/.keep_app-containers_skopeo-0", 53 Digest: &file.Digest{ 54 Algorithm: "md5", 55 Value: "d41d8cd98f00b204e9800998ecf8427e", 56 }, 57 }, 58 }, 59 }, 60 }, 61 } 62 63 // TODO: relationships are not under test yet 64 var expectedRelationships []artifact.Relationship 65 66 pkgtest.NewCatalogTester(). 67 FromDirectory(t, "test-fixtures/image-portage"). 68 Expects(expectedPkgs, expectedRelationships). 69 TestCataloger(t, NewPortageCataloger()) 70 71 } 72 73 func TestCataloger_Globs(t *testing.T) { 74 tests := []struct { 75 name string 76 fixture string 77 expected []string 78 }{ 79 { 80 name: "obtain portage contents file", 81 fixture: "test-fixtures/glob-paths", 82 expected: []string{ 83 "var/db/pkg/x/y/CONTENTS", 84 }, 85 }, 86 } 87 88 for _, test := range tests { 89 t.Run(test.name, func(t *testing.T) { 90 pkgtest.NewCatalogTester(). 91 FromDirectory(t, test.fixture). 92 ExpectsResolverContentQueries(test.expected). 93 TestCataloger(t, NewPortageCataloger()) 94 }) 95 } 96 }