github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/dotnet/package_test.go (about) 1 package dotnet 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_getDepsJSONFilePrefix(t *testing.T) { 10 tests := []struct { 11 name string 12 path string 13 want string 14 }{ 15 { 16 name: "windows-style full path", 17 path: `C:\Code\Projects\My-Project\My.Rest.Project.deps.json`, 18 want: "My.Rest.Project", 19 }, 20 { 21 name: "leading backslash", 22 path: `\My.Project.deps.json`, 23 want: "My.Project", 24 }, 25 { 26 name: "unix-style path with lots of prefixes", 27 path: "/my/cool/project/cool-project.deps.json", 28 want: "cool-project", 29 }, 30 { 31 name: "unix-style relative path", 32 path: "cool-project/my-dotnet-project.deps.json", 33 want: "my-dotnet-project", 34 }, 35 } 36 for _, tt := range tests { 37 t.Run(tt.name, func(t *testing.T) { 38 assert.Equalf(t, tt.want, getDepsJSONFilePrefix(tt.path), "getDepsJSONFilePrefix(%v)", tt.path) 39 }) 40 } 41 }