github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/nix/cataloger_test.go (about) 1 package nix 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 TestCataloger_Catalog(t *testing.T) { 13 14 tests := []struct { 15 fixture string 16 wantPkgs []pkg.Package 17 wantRel []artifact.Relationship 18 }{ 19 { 20 fixture: "test-fixtures/fixture-1", 21 wantPkgs: []pkg.Package{ 22 { 23 Name: "glibc", 24 Version: "2.34-210", 25 PURL: "pkg:nix/glibc@2.34-210?output=bin&outputhash=h0cnbmfcn93xm5dg2x27ixhag1cwndga", 26 Locations: file.NewLocationSet(file.NewLocation("nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin")), 27 FoundBy: catalogerName, 28 Type: pkg.NixPkg, 29 MetadataType: pkg.NixStoreMetadataType, 30 Metadata: pkg.NixStoreMetadata{ 31 OutputHash: "h0cnbmfcn93xm5dg2x27ixhag1cwndga", 32 Output: "bin", 33 Files: []string{ 34 "nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/lib", 35 "nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/lib/glibc.so", 36 "nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/share", 37 "nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/share/man", 38 "nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/share/man/glibc.1", 39 }, 40 }, 41 }, 42 }, 43 }, 44 } 45 for _, tt := range tests { 46 t.Run(tt.fixture, func(t *testing.T) { 47 c := NewStoreCataloger() 48 49 pkgtest.NewCatalogTester(). 50 FromDirectory(t, tt.fixture). 51 Expects(tt.wantPkgs, tt.wantRel). 52 TestCataloger(t, c) 53 }) 54 } 55 }