github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/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/lineaje-labs/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  					Metadata: pkg.NixStoreEntry{
    30  						OutputHash: "h0cnbmfcn93xm5dg2x27ixhag1cwndga",
    31  						Output:     "bin",
    32  						Files: []string{
    33  							"nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/lib",
    34  							"nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/lib/glibc.so",
    35  							"nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/share",
    36  							"nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/share/man",
    37  							"nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin/share/man/glibc.1",
    38  						},
    39  					},
    40  				},
    41  			},
    42  		},
    43  	}
    44  	for _, tt := range tests {
    45  		t.Run(tt.fixture, func(t *testing.T) {
    46  			c := NewStoreCataloger()
    47  
    48  			pkgtest.NewCatalogTester().
    49  				FromDirectory(t, tt.fixture).
    50  				Expects(tt.wantPkgs, tt.wantRel).
    51  				TestCataloger(t, c)
    52  		})
    53  	}
    54  }