github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/pkg/cataloger/cpp/parse_conaninfo_test.go (about) 1 package cpp 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 TestParseConaninfo(t *testing.T) { 13 fixture := "test-fixtures/conaninfo/mfast/1.2.2/my_user/my_channel/package/9d1f076b471417647c2022a78d5e2c1f834289ac/conaninfo.txt" 14 expected := []pkg.Package{ 15 { 16 Name: "mfast", 17 Version: "1.2.2", 18 PURL: "pkg:conan/my_user/mfast@1.2.2?channel=my_channel", 19 Locations: file.NewLocationSet(file.NewLocation(fixture)), 20 Language: pkg.CPP, 21 Type: pkg.ConanPkg, 22 Metadata: pkg.ConaninfoEntry{ 23 Ref: "mfast/1.2.2@my_user/my_channel#c6f6387c9b99780f0ee05e25f99d0f39", 24 PackageID: "9d1f076b471417647c2022a78d5e2c1f834289ac", 25 }, 26 }, 27 { 28 Name: "boost", 29 Version: "1.75.0", 30 PURL: "pkg:conan/boost@1.75.0", 31 Locations: file.NewLocationSet(file.NewLocation(fixture)), 32 Language: pkg.CPP, 33 Type: pkg.ConanPkg, 34 Metadata: pkg.ConaninfoEntry{ 35 Ref: "boost/1.75.0:dc8aedd23a0f0a773a5fcdcfe1ae3e89c4205978", 36 PackageID: "dc8aedd23a0f0a773a5fcdcfe1ae3e89c4205978", 37 }, 38 }, 39 { 40 Name: "zlib", 41 Version: "1.2.13", 42 PURL: "pkg:conan/zlib@1.2.13", 43 Locations: file.NewLocationSet(file.NewLocation(fixture)), 44 Language: pkg.CPP, 45 Type: pkg.ConanPkg, 46 Metadata: pkg.ConaninfoEntry{ 47 Ref: "zlib/1.2.13:dfbe50feef7f3c6223a476cd5aeadb687084a646", 48 PackageID: "dfbe50feef7f3c6223a476cd5aeadb687084a646", 49 }, 50 }, 51 { 52 Name: "bzip2", 53 Version: "1.0.8", 54 PURL: "pkg:conan/bzip2@1.0.8", 55 Locations: file.NewLocationSet(file.NewLocation(fixture)), 56 Language: pkg.CPP, 57 Type: pkg.ConanPkg, 58 Metadata: pkg.ConaninfoEntry{ 59 Ref: "bzip2/1.0.8:c32092bf4d4bb47cf962af898e02823f499b017e", 60 PackageID: "c32092bf4d4bb47cf962af898e02823f499b017e", 61 }, 62 }, 63 { 64 Name: "libbacktrace", 65 Version: "cci.20210118", 66 PURL: "pkg:conan/libbacktrace@cci.20210118", 67 Locations: file.NewLocationSet(file.NewLocation(fixture)), 68 Language: pkg.CPP, 69 Type: pkg.ConanPkg, 70 Metadata: pkg.ConaninfoEntry{ 71 Ref: "libbacktrace/cci.20210118:dfbe50feef7f3c6223a476cd5aeadb687084a646", 72 PackageID: "dfbe50feef7f3c6223a476cd5aeadb687084a646", 73 }, 74 }, 75 { 76 Name: "tinyxml2", 77 Version: "9.0.0", 78 PURL: "pkg:conan/tinyxml2@9.0.0", 79 Locations: file.NewLocationSet(file.NewLocation(fixture)), 80 Language: pkg.CPP, 81 Type: pkg.ConanPkg, 82 Metadata: pkg.ConaninfoEntry{ 83 Ref: "tinyxml2/9.0.0:6557f18ca99c0b6a233f43db00e30efaa525e27e", 84 PackageID: "6557f18ca99c0b6a233f43db00e30efaa525e27e", 85 }, 86 }, 87 } 88 89 // relationships require IDs to be set to be sorted similarly 90 for i := range expected { 91 expected[i].SetID() 92 } 93 94 var expectedRelationships = []artifact.Relationship{ 95 { 96 From: expected[1], // boost 97 To: expected[0], // mfast 98 Type: artifact.DependencyOfRelationship, 99 Data: nil, 100 }, 101 { 102 From: expected[5], // tinyxml2 103 To: expected[0], // mfast 104 Type: artifact.DependencyOfRelationship, 105 Data: nil, 106 }, 107 { 108 From: expected[2], // zlib 109 To: expected[0], // mfast 110 Type: artifact.DependencyOfRelationship, 111 Data: nil, 112 }, 113 { 114 From: expected[3], // bzip2 115 To: expected[0], // mfast 116 Type: artifact.DependencyOfRelationship, 117 Data: nil, 118 }, 119 { 120 From: expected[4], // libbacktrace 121 To: expected[0], // mfast 122 Type: artifact.DependencyOfRelationship, 123 Data: nil, 124 }, 125 } 126 127 pkgtest.TestFileParser(t, fixture, parseConaninfo, expected, expectedRelationships) 128 }