github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/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  		want      string
    15  	}{
    16  		{
    17  			name: "name + version",
    18  			storePath: nixStorePath{
    19  				name:    "glibc",
    20  				version: "2.34",
    21  			},
    22  			want: "pkg:nix/glibc@2.34",
    23  		},
    24  		{
    25  			name: "hash qualifier",
    26  			storePath: nixStorePath{
    27  				name:       "glibc",
    28  				version:    "2.34",
    29  				outputHash: "h0cnbmfcn93xm5dg2x27ixhag1cwndga",
    30  			},
    31  			want: "pkg:nix/glibc@2.34?outputhash=h0cnbmfcn93xm5dg2x27ixhag1cwndga",
    32  		},
    33  		{
    34  			name: "output qualifier",
    35  			storePath: nixStorePath{
    36  				name:       "glibc",
    37  				version:    "2.34",
    38  				outputHash: "h0cnbmfcn93xm5dg2x27ixhag1cwndga",
    39  				output:     "bin",
    40  			},
    41  			want: "pkg:nix/glibc@2.34?output=bin&outputhash=h0cnbmfcn93xm5dg2x27ixhag1cwndga",
    42  		},
    43  	}
    44  	for _, tt := range tests {
    45  		t.Run(tt.name, func(t *testing.T) {
    46  			assert.Equal(t, tt.want, packageURL(tt.storePath))
    47  		})
    48  	}
    49  }