github.com/google/osv-scalibr@v0.4.1/extractor/filesystem/language/golang/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 gopurl "github.com/google/osv-scalibr/extractor/filesystem/language/golang/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: "split_name_namespace", 34 name: "github.com/google/osv-scalibr", 35 version: "1.2.3", 36 want: &purl.PackageURL{ 37 Type: purl.TypeGolang, 38 Name: "osv-scalibr", 39 Namespace: "github.com/google", 40 Version: "1.2.3", 41 }, 42 }, 43 { 44 desc: "mixed_case_name_namespace", 45 name: "github.com/Microsoft/Go-Rustaudit", 46 version: "1.2.3", 47 want: &purl.PackageURL{ 48 Type: purl.TypeGolang, 49 Name: "go-rustaudit", 50 Namespace: "github.com/microsoft", 51 Version: "1.2.3", 52 }, 53 }, 54 { 55 desc: "no_namespace", 56 name: "name", 57 version: "1.2.3", 58 want: &purl.PackageURL{ 59 Type: purl.TypeGolang, 60 Name: "name", 61 Version: "1.2.3", 62 }, 63 }, 64 } 65 66 for _, tt := range tests { 67 t.Run(tt.desc, func(t *testing.T) { 68 got := gopurl.MakePackageURL(tt.name, tt.version) 69 if diff := cmp.Diff(tt.want, got); diff != "" { 70 t.Errorf("MakePackageURL() returned unexpected diff (-want +got):\n%s", diff) 71 } 72 }) 73 } 74 }