github.com/google/osv-scalibr@v0.4.1/extractor/filesystem/language/erlang/mixlock/purl/purl_test.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package purl_test
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/google/go-cmp/cmp"
    21  	mixlockpurl "github.com/google/osv-scalibr/extractor/filesystem/language/erlang/mixlock/purl"
    22  	"github.com/google/osv-scalibr/purl"
    23  )
    24  
    25  func TestMakePackageURL(t *testing.T) {
    26  	tests := []struct {
    27  		desc    string
    28  		name    string
    29  		version string
    30  		want    *purl.PackageURL
    31  	}{
    32  		{
    33  			desc:    "lowercase_name",
    34  			name:    "name",
    35  			version: "version",
    36  			want: &purl.PackageURL{
    37  				Type:    purl.TypeHex,
    38  				Name:    "name",
    39  				Version: "version",
    40  			},
    41  		},
    42  		{
    43  			desc:    "mixed_case_gets_converted",
    44  			name:    "Name",
    45  			version: "version",
    46  			want: &purl.PackageURL{
    47  				Type:    purl.TypeHex,
    48  				Name:    "name",
    49  				Version: "version",
    50  			},
    51  		},
    52  	}
    53  
    54  	for _, tt := range tests {
    55  		t.Run(tt.desc, func(t *testing.T) {
    56  			got := mixlockpurl.MakePackageURL(tt.name, tt.version)
    57  			if diff := cmp.Diff(tt.want, got); diff != "" {
    58  				t.Errorf("mixlockpurl.MakePackageURL(%v, %v): unexpected PURL (-want +got):\n%s", tt.name, tt.version, diff)
    59  			}
    60  		})
    61  	}
    62  }