fix file name bug

This commit is contained in:
kvii 2022-11-07 22:13:34 +08:00
parent cf71c4fb6c
commit a38ee8d578
3 changed files with 41 additions and 8 deletions

View File

@ -1,9 +1,8 @@
//go:build unix
// +build unix
package utils package utils
import "testing" import (
"testing"
)
func TestSourceDir(t *testing.T) { func TestSourceDir(t *testing.T) {
cases := []struct { cases := []struct {

35
utils/utils_linux_test.go Normal file
View File

@ -0,0 +1,35 @@
package utils
import (
"testing"
)
func TestSourceDir(t *testing.T) {
cases := []struct {
file string
want string
}{
{
file: "/Users/name/go/pkg/mod/gorm.io/gorm@v1.2.3/utils/utils.go",
want: "/Users/name/go/pkg/mod/gorm.io/",
},
{
file: "/go/work/proj/gorm/utils/utils.go",
want: "/go/work/proj/gorm/",
},
{
file: "/go/work/proj/gorm_alias/utils/utils.go",
want: "/go/work/proj/gorm_alias/",
},
{
file: "/go/work/proj/my.gorm.io/gorm@v1.2.3/utils/utils.go",
want: "/go/work/proj/my.gorm.io/gorm@v1.2.3/",
},
}
for _, c := range cases {
s := sourceDir(c.file)
if s != c.want {
t.Fatalf("%s: expected %s, got %s", c.file, c.want, s)
}
}
}

View File

@ -1,9 +1,8 @@
//go:build windows
// +build windows
package utils package utils
import "testing" import (
"testing"
)
func TestSourceDir(t *testing.T) { func TestSourceDir(t *testing.T) {
cases := []struct { cases := []struct {