github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/homebrew/cataloger_test.go (about) 1 package homebrew 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_HomebrewCataloger_Globs(t *testing.T) { 13 fixture := "test-fixtures/install-example" 14 15 expected := []string{ 16 "opt/homebrew/Cellar/foo/1.2.3/.brew/foo.rb", 17 "opt/homebrew/Library/Taps/testorg/sometap/Formula/bar.rb", 18 } 19 20 pkgtest.NewCatalogTester(). 21 FromDirectory(t, fixture). 22 ExpectsResolverContentQueries(expected). 23 TestCataloger(t, NewCataloger()) 24 } 25 26 func Test_HomebrewCataloger(t *testing.T) { 27 28 tests := []struct { 29 name string 30 path string 31 expected []pkg.Package 32 expectedRels []artifact.Relationship 33 }{ 34 { 35 name: "go case", 36 path: "test-fixtures/install-example", 37 expected: []pkg.Package{ 38 { 39 Name: "bar", 40 Version: "4.5.6", 41 Type: pkg.HomebrewPkg, 42 Locations: file.NewLocationSet( 43 file.NewLocation("opt/homebrew/Library/Taps/testorg/sometap/Formula/bar.rb").WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), 44 ), 45 Licenses: pkg.NewLicenseSet(pkg.NewLicensesFromValues("MIT")...), 46 FoundBy: "homebrew-cataloger", 47 PURL: "pkg:brew/bar@4.5.6", 48 Metadata: pkg.HomebrewFormula{ 49 Tap: "testorg/sometap", 50 Homepage: "https://example.com/bar", 51 Description: "A test Homebrew formula for bar", 52 }, 53 }, 54 { 55 Name: "foo", 56 Version: "1.2.3", 57 Type: pkg.HomebrewPkg, 58 Locations: file.NewLocationSet( 59 file.NewLocation("opt/homebrew/Cellar/foo/1.2.3/.brew/foo.rb").WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), 60 ), 61 Licenses: pkg.NewLicenseSet(pkg.NewLicensesFromValues("Apache 2.0")...), 62 FoundBy: "homebrew-cataloger", 63 PURL: "pkg:brew/foo@1.2.3", 64 Metadata: pkg.HomebrewFormula{ 65 Homepage: "https://example.com/foo", 66 Description: "A test Homebrew formula for Foo", 67 }, 68 }, 69 }, 70 }, 71 } 72 73 for _, tt := range tests { 74 t.Run(tt.name, func(t *testing.T) { 75 pkgtest.NewCatalogTester(). 76 FromDirectory(t, tt.path). 77 Expects(tt.expected, tt.expectedRels). 78 TestCataloger(t, NewCataloger()) 79 }) 80 } 81 82 }