github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/pkg/cataloger/arch/cataloger_test.go (about) 1 package arch 2 3 import ( 4 "testing" 5 6 "github.com/google/go-cmp/cmp/cmpopts" 7 8 "github.com/anchore/syft/syft/artifact" 9 "github.com/anchore/syft/syft/file" 10 "github.com/anchore/syft/syft/pkg" 11 "github.com/lineaje-labs/syft/syft/pkg/cataloger/internal/pkgtest" 12 ) 13 14 func TestAlpmCataloger(t *testing.T) { 15 dbLocation := file.NewLocation("var/lib/pacman/local/gmp-6.2.1-2/desc") 16 expectedPkgs := []pkg.Package{ 17 { 18 Name: "gmp", 19 Version: "6.2.1-2", 20 Type: pkg.AlpmPkg, 21 FoundBy: "alpm-db-cataloger", 22 Licenses: pkg.NewLicenseSet( 23 pkg.NewLicenseFromLocations("LGPL3", dbLocation), 24 pkg.NewLicenseFromLocations("GPL", dbLocation), 25 ), 26 Locations: file.NewLocationSet(dbLocation), 27 CPEs: nil, 28 PURL: "", 29 Metadata: pkg.AlpmDBEntry{ 30 BasePackage: "gmp", 31 Package: "gmp", 32 Version: "6.2.1-2", 33 Description: "A free library for arbitrary precision arithmetic", 34 Architecture: "x86_64", 35 Size: 1044438, 36 Packager: "Antonio Rojas <arojas@archlinux.org>", 37 URL: "https://gmplib.org/", 38 Validation: "pgp", 39 Reason: 1, 40 Files: []pkg.AlpmFileRecord{ 41 { 42 Path: "/usr", 43 Type: "dir", 44 Digests: []file.Digest{}, 45 }, 46 { 47 Path: "/usr/include", 48 Type: "dir", 49 Digests: []file.Digest{}, 50 }, 51 { 52 Path: "/usr/include/gmp.h", 53 Size: "84140", 54 Digests: []file.Digest{ 55 {Algorithm: "md5", Value: "76595f70565c72550eb520809bf86856"}, 56 {Algorithm: "sha256", Value: "91a614b9202453153fe3b7512d15e89659108b93ce8841c8e13789eb85da9e3a"}, 57 }, 58 }, 59 { 60 Path: "/usr/include/gmpxx.h", 61 Size: "129113", 62 Digests: []file.Digest{ 63 {Algorithm: "md5", Value: "ea3d21de4bcf7c696799c5c55dd3655b"}, 64 {Algorithm: "sha256", Value: "0011ae411a0bc1030e07d968b32fdc1343f5ac2a17b7d28f493e7976dde2ac82"}, 65 }, 66 }, 67 { 68 Path: "/usr/lib", 69 Type: "dir", 70 Digests: []file.Digest{}, 71 }, 72 { 73 Path: "/usr/lib/libgmp.so", 74 Type: "link", 75 Link: "libgmp.so.10.4.1", 76 Digests: []file.Digest{}, 77 }, 78 { 79 Path: "/usr/lib/libgmp.so.10", 80 Type: "link", 81 Link: "libgmp.so.10.4.1", 82 Digests: []file.Digest{}, 83 }, 84 { 85 Path: "/usr/lib/libgmp.so.10.4.1", 86 Size: "663224", 87 Digests: []file.Digest{ 88 {Algorithm: "md5", Value: "d6d03eadacdd9048d5b2adf577e9d722"}, 89 {Algorithm: "sha256", Value: "39898bd3d8d6785222432fa8b8aef7ce3b7e5bbfc66a52b7c0da09bed4adbe6a"}, 90 }, 91 }, 92 { 93 Path: "/usr/lib/libgmpxx.so", 94 Type: "link", 95 Link: "libgmpxx.so.4.6.1", 96 Digests: []file.Digest{}, 97 }, 98 { 99 Path: "/usr/lib/libgmpxx.so.4", 100 Type: "link", 101 Link: "libgmpxx.so.4.6.1", 102 Digests: []file.Digest{}, 103 }, 104 { 105 Path: "/usr/lib/libgmpxx.so.4.6.1", 106 Size: "30680", 107 Digests: []file.Digest{ 108 {Algorithm: "md5", Value: "dd5f0c4d635fa599fa7f4339c0e8814d"}, 109 {Algorithm: "sha256", Value: "0ef67cbde4841f58d2e4b41f59425eb87c9eeaf4e649c060b326342c53bedbec"}, 110 }, 111 }, 112 { 113 Path: "/usr/lib/pkgconfig", 114 Type: "dir", 115 Digests: []file.Digest{}, 116 }, 117 { 118 Path: "/usr/lib/pkgconfig/gmp.pc", 119 Size: "245", 120 Digests: []file.Digest{ 121 {Algorithm: "md5", Value: "a91a9f1b66218cb77b9cd2cdf341756d"}, 122 {Algorithm: "sha256", Value: "4e9de547a48c4e443781e9fa702a1ec5a23ee28b4bc520306cff2541a855be37"}, 123 }, 124 }, 125 { 126 Path: "/usr/lib/pkgconfig/gmpxx.pc", 127 Size: "280", 128 Digests: []file.Digest{ 129 {Algorithm: "md5", Value: "8c0f54e987934352177a6a30a811b001"}, 130 {Algorithm: "sha256", Value: "fc5dbfbe75977057ba50953d94b9daecf696c9fdfe5b94692b832b44ecca871b"}, 131 }, 132 }, 133 { 134 Path: "/usr/share", 135 Type: "dir", 136 Digests: []file.Digest{}, 137 }, 138 { 139 Path: "/usr/share/info", 140 Type: "dir", 141 Digests: []file.Digest{}, 142 }, 143 { 144 Path: "/usr/share/info/gmp.info-1.gz", 145 Size: "85892", 146 Digests: []file.Digest{ 147 {Algorithm: "md5", Value: "63304d4d2f0247fb8a999fae66a81c19"}, 148 {Algorithm: "sha256", Value: "86288c1531a2789db5da8b9838b5cde4db07bda230ae11eba23a1f33698bd14e"}, 149 }, 150 }, 151 { 152 Path: "/usr/share/info/gmp.info-2.gz", 153 Size: "48484", 154 Digests: []file.Digest{ 155 {Algorithm: "md5", Value: "4bb0dadec416d305232cac6eae712ff7"}, 156 {Algorithm: "sha256", Value: "b7443c1b529588d98a074266087f79b595657ac7274191c34b10a9ceedfa950e"}, 157 }, 158 }, 159 { 160 Path: "/usr/share/info/gmp.info.gz", 161 Size: "2380", 162 Digests: []file.Digest{ 163 {Algorithm: "md5", Value: "cf6880fb0d862ee1da0d13c3831b5720"}, 164 {Algorithm: "sha256", Value: "a13c8eecda3f3e5ad1e09773e47a9686f07d9d494eaddf326f3696bbef1548fd"}, 165 }, 166 }, 167 }, 168 Backup: []pkg.AlpmFileRecord{}, 169 }, 170 }, 171 } 172 173 // TODO: relationships are not under test yet 174 var expectedRelationships []artifact.Relationship 175 176 pkgtest.NewCatalogTester(). 177 FromDirectory(t, "test-fixtures/gmp-fixture"). 178 WithCompareOptions(cmpopts.IgnoreFields(pkg.AlpmFileRecord{}, "Time")). 179 Expects(expectedPkgs, expectedRelationships). 180 TestCataloger(t, NewDBCataloger()) 181 182 } 183 184 func TestCataloger_Globs(t *testing.T) { 185 tests := []struct { 186 name string 187 fixture string 188 expected []string 189 }{ 190 { 191 name: "obtain description files", 192 fixture: "test-fixtures/glob-paths", 193 expected: []string{ 194 "var/lib/pacman/local/base-1.0/desc", 195 "var/lib/pacman/local/dive-0.10.0/desc", 196 }, 197 }, 198 } 199 200 for _, test := range tests { 201 t.Run(test.name, func(t *testing.T) { 202 pkgtest.NewCatalogTester(). 203 FromDirectory(t, test.fixture). 204 ExpectsResolverContentQueries(test.expected). 205 IgnoreUnfulfilledPathResponses("var/lib/pacman/local/base-1.0/mtree", "var/lib/pacman/local/dive-0.10.0/mtree"). 206 TestCataloger(t, NewDBCataloger()) 207 }) 208 } 209 }