github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/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/lineaje-labs/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 Metadata: pkg.LinuxKernel{ 26 Name: "", 27 Architecture: "x86", 28 Version: "6.0.7-301.fc37.x86_64", 29 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", 30 BuildTime: "", 31 Author: "", 32 Format: "bzImage", 33 RWRootFS: false, 34 SwapDevice: 0, 35 RootDevice: 0, 36 VideoMode: "Video mode 65535", 37 }, 38 } 39 40 kernelModulePkg := pkg.Package{ 41 Name: "ttynull", 42 Version: "", 43 FoundBy: "linux-kernel-cataloger", 44 Locations: file.NewLocationSet( 45 file.NewVirtualLocation("/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 46 "/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 47 ), 48 ), 49 Licenses: pkg.NewLicenseSet( 50 pkg.NewLicenseFromLocations("GPL v2", 51 file.NewVirtualLocation( 52 "/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 53 "/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 54 ), 55 ), 56 ), 57 Type: pkg.LinuxKernelModulePkg, 58 PURL: "pkg:generic/ttynull", 59 Metadata: pkg.LinuxKernelModule{ 60 Name: "ttynull", 61 Version: "", 62 SourceVersion: "", 63 License: "GPL v2", 64 Path: "/lib/modules/6.0.7-301.fc37.x86_64/kernel/drivers/tty/ttynull.ko", 65 Description: "", 66 KernelVersion: "6.0.7-301.fc37.x86_64", 67 VersionMagic: "6.0.7-301.fc37.x86_64 SMP preempt mod_unload ", 68 Parameters: map[string]pkg.LinuxKernelModuleParameter{}, 69 }, 70 } 71 72 expectedPkgs := []pkg.Package{ 73 kernelPkg, 74 kernelModulePkg, 75 } 76 expectedRelationships := []artifact.Relationship{ 77 { 78 From: kernelPkg, 79 To: kernelModulePkg, 80 Type: artifact.DependencyOfRelationship, 81 }, 82 } 83 84 pkgtest.NewCatalogTester(). 85 WithImageResolver(t, "image-kernel-and-modules"). 86 IgnoreLocationLayer(). 87 Expects(expectedPkgs, expectedRelationships). 88 TestCataloger(t, 89 NewLinuxKernelCataloger( 90 LinuxKernelCatalogerConfig{ 91 CatalogModules: true, 92 }, 93 ), 94 ) 95 }