github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/rust/cataloger_test.go (about) 1 package rust 2 3 import ( 4 "testing" 5 6 "github.com/anchore/syft/syft/file" 7 "github.com/anchore/syft/syft/pkg" 8 "github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest" 9 ) 10 11 func TestNewAuditBinaryCataloger(t *testing.T) { 12 13 expectedPkgs := []pkg.Package{ 14 { 15 Name: "auditable", 16 Version: "0.1.0", 17 PURL: "pkg:cargo/auditable@0.1.0", 18 FoundBy: "cargo-auditable-binary-cataloger", 19 Locations: file.NewLocationSet(file.NewVirtualLocation("/hello-auditable", "/hello-auditable")), 20 Language: pkg.Rust, 21 Type: pkg.RustPkg, 22 MetadataType: pkg.RustCargoPackageMetadataType, 23 Metadata: pkg.CargoPackageMetadata{ 24 Name: "auditable", 25 Version: "0.1.0", 26 Source: "local", 27 }, 28 }, 29 { 30 Name: "hello-auditable", 31 Version: "0.1.0", 32 PURL: "pkg:cargo/hello-auditable@0.1.0", 33 FoundBy: "cargo-auditable-binary-cataloger", 34 Locations: file.NewLocationSet(file.NewVirtualLocation("/hello-auditable", "/hello-auditable")), 35 Language: pkg.Rust, 36 Type: pkg.RustPkg, 37 MetadataType: pkg.RustCargoPackageMetadataType, 38 Metadata: pkg.CargoPackageMetadata{ 39 Name: "hello-auditable", 40 Version: "0.1.0", 41 Source: "local", 42 }, 43 }, 44 } 45 46 pkgtest.NewCatalogTester(). 47 WithImageResolver(t, "image-audit"). 48 IgnoreLocationLayer(). // this fixture can be rebuilt, thus the layer ID will change 49 Expects(expectedPkgs, nil). 50 TestCataloger(t, NewAuditBinaryCataloger()) 51 } 52 53 func Test_CargoLockCataloger_Globs(t *testing.T) { 54 tests := []struct { 55 name string 56 fixture string 57 expected []string 58 }{ 59 { 60 name: "obtain Cargo.lock files", 61 fixture: "test-fixtures/glob-paths", 62 expected: []string{ 63 "src/Cargo.lock", 64 }, 65 }, 66 } 67 68 for _, test := range tests { 69 t.Run(test.name, func(t *testing.T) { 70 pkgtest.NewCatalogTester(). 71 FromDirectory(t, test.fixture). 72 ExpectsResolverContentQueries(test.expected). 73 TestCataloger(t, NewCargoLockCataloger()) 74 }) 75 } 76 } 77 78 func Test_AuditBinaryCataloger_Globs(t *testing.T) { 79 tests := []struct { 80 name string 81 fixture string 82 expected []string 83 }{ 84 { 85 name: "obtain audit binary files", 86 fixture: "test-fixtures/glob-paths", 87 expected: []string{ 88 "partial-binary", 89 }, 90 }, 91 } 92 93 for _, test := range tests { 94 t.Run(test.name, func(t *testing.T) { 95 pkgtest.NewCatalogTester(). 96 FromDirectory(t, test.fixture). 97 ExpectsResolverContentQueries(test.expected). 98 TestCataloger(t, NewAuditBinaryCataloger()) 99 }) 100 } 101 }