github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/nix/package_test.go (about)

     1  package nix
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_packageURL(t *testing.T) {
    10  
    11  	tests := []struct {
    12  		name      string
    13  		storePath nixStorePath
    14  		drvPath   string
    15  		want      string
    16  	}{
    17  		{
    18  			name: "name + version",
    19  			storePath: nixStorePath{
    20  				Name:    "glibc",
    21  				Version: "2.34",
    22  			},
    23  			want: "pkg:nix/glibc@2.34",
    24  		},
    25  		{
    26  			name: "hash qualifier",
    27  			storePath: nixStorePath{
    28  				Name:       "glibc",
    29  				Version:    "2.34",
    30  				OutputHash: "h0cnbmfcn93xm5dg2x27ixhag1cwndga",
    31  			},
    32  			want: "pkg:nix/glibc@2.34?outputhash=h0cnbmfcn93xm5dg2x27ixhag1cwndga",
    33  		},
    34  		{
    35  			name: "output qualifier",
    36  			storePath: nixStorePath{
    37  				Name:       "glibc",
    38  				Version:    "2.34",
    39  				OutputHash: "h0cnbmfcn93xm5dg2x27ixhag1cwndga",
    40  				Output:     "bin",
    41  			},
    42  			want: "pkg:nix/glibc@2.34?output=bin&outputhash=h0cnbmfcn93xm5dg2x27ixhag1cwndga",
    43  		},
    44  		{
    45  			name: "derivation qualifier",
    46  			storePath: nixStorePath{
    47  				Name:    "glibc",
    48  				Version: "2.34",
    49  			},
    50  			drvPath: "/nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34.drv",
    51  			want:    "pkg:nix/glibc@2.34?drvpath=h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34.drv",
    52  		},
    53  	}
    54  	for _, tt := range tests {
    55  		t.Run(tt.name, func(t *testing.T) {
    56  			assert.Equal(t, tt.want, packageURL(tt.storePath, tt.drvPath))
    57  		})
    58  	}
    59  }