github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/kernel/cataloger_test.go (about) 1 package kernel 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/anchore/syft/syft/pkg/cataloger/internal/pkgtest" 10 ) 11 12 func Test_KernelCataloger(t *testing.T) { 13 kernelPkg := pkg.Package{ 14 Name: "linux-kernel", 15 Version: "6.0.7-301.fc37.x86_64", 16 FoundBy: "linux-kernel-cataloger", 17 Locations: file.NewLocationSet( 18 file.NewVirtualLocation( 19 "/lib/modules/6.0.7-301.fc37.x86_64/vmlinuz", 20 "/lib/modules/6.0.7-301.fc37.x86_64/vmlinuz", 21 ), 22 ), 23 Type: pkg.LinuxKernelPkg, 24 PURL: "pkg:generic/linux-kernel@6.0.7-301.fc37.x86_64", 25 MetadataType: pkg.LinuxKernelMetadataType, 26 Metadata: pkg.LinuxKernelMetadata{ 27 Name: "", 28 Architecture: "x86", 29 Version: "6.0.7-301.fc37.x86_64", 30 ExtendedVersion: "6.0.7-301.fc37.x86_64 (mockbuild@bkernel01.iad2.fedoraproject.org) #1 SMP PREEMPT_DYNAMIC Fri Nov 4 18:35:48 UTC 2022", 31 BuildTime: "", 32 Author: "", 33 Format: "bzImage", 34 RWRootFS: false, 35 SwapDevice: 0, 36 RootDevice: 0, 37 VideoMode: "Video mode 65535", 38 }, 39 } 40 41 kernelModulePkg := pkg.Package{ 42 Name: "ttynull", 43 Version: "", 44 FoundBy: "linux-kernel-cataloger", 45 Locations: file.NewLocationSet( 46 file.NewVirtualLocation("/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 47 "/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 48 ), 49 ), 50 Licenses: pkg.NewLicenseSet( 51 pkg.NewLicenseFromLocations("GPL v2", 52 file.NewVirtualLocation( 53 "/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 54 "/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 55 ), 56 ), 57 ), 58 Type: pkg.LinuxKernelModulePkg, 59 PURL: "pkg:generic/ttynull", 60 MetadataType: pkg.LinuxKernelModuleMetadataType, 61 Metadata: pkg.LinuxKernelModuleMetadata{ 62 Name: "ttynull", 63 Version: "", 64 SourceVersion: "", 65 License: "GPL v2", 66 Path: "/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 67 Description: "", 68 KernelVersion: "6.0.7-301.fc37.x86_64", 69 VersionMagic: "6.0.7-301.fc37.x86_64 SMP preempt mod_unload ", 70 Parameters: map[string]pkg.LinuxKernelModuleParameter{}, 71 }, 72 } 73 74 expectedPkgs := []pkg.Package{ 75 kernelPkg, 76 kernelModulePkg, 77 } 78 expectedRelationships := []artifact.Relationship{ 79 { 80 From: kernelPkg, 81 To: kernelModulePkg, 82 Type: artifact.DependencyOfRelationship, 83 }, 84 } 85 86 pkgtest.NewCatalogTester(). 87 WithImageResolver(t, "image-kernel-and-modules"). 88 IgnoreLocationLayer(). 89 Expects(expectedPkgs, expectedRelationships). 90 TestCataloger(t, 91 NewLinuxKernelCataloger( 92 LinuxCatalogerConfig{ 93 CatalogModules: true, 94 }, 95 ), 96 ) 97 }