github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/binary/pe_package_cataloger_test.go (about) 1 package binary 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/anchore/syft/syft/file" 9 "github.com/anchore/syft/syft/pkg" 10 "github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest" 11 ) 12 13 func Test_PEPackageCataloger(t *testing.T) { 14 cases := []struct { 15 name string 16 fixture string 17 expected []pkg.Package 18 wantErr require.ErrorAssertionFunc 19 }{ 20 { 21 name: "non-.NET package", 22 fixture: "image-jruby", 23 expected: []pkg.Package{ 24 { 25 Name: "JRuby", 26 Version: "9.3.15.0", 27 Type: pkg.BinaryPkg, 28 Locations: file.NewLocationSet( 29 file.NewLocation("/jruby_windows_9_3_15_0.exe"), 30 ), 31 FoundBy: "pe-binary-package-cataloger", 32 Metadata: pkg.PEBinary{ 33 VersionResources: pkg.KeyValues{ 34 {Key: "CompanyName", Value: "JRuby Dev Team"}, 35 {Key: "FileDescription", Value: "JRuby"}, 36 {Key: "FileVersion", Value: "9.3.15.0"}, 37 {Key: "InternalName", Value: "jruby"}, 38 {Key: "LegalCopyright", Value: "JRuby Dev Team"}, 39 {Key: "OriginalFilename", Value: "jruby_windows-x32_9_3_15_0.exe"}, 40 {Key: "ProductName", Value: "JRuby"}, 41 {Key: "ProductVersion", Value: "9.3.15.0"}, 42 }, 43 }, 44 }, 45 }, 46 }, 47 { 48 name: "ignore .NET packages", 49 fixture: "image-dotnet-app", 50 expected: nil, // expect nothing! 51 }, 52 } 53 54 for _, v := range cases { 55 t.Run(v.name, func(t *testing.T) { 56 pkgtest.NewCatalogTester(). 57 WithImageResolver(t, v.fixture). 58 IgnoreLocationLayer(). // this fixture can be rebuilt, thus the layer ID will change 59 Expects(v.expected, nil). 60 TestCataloger(t, NewPEPackageCataloger()) 61 }) 62 } 63 64 }