gohttp/utils/util_test.go

54 lines
983 B
Go
Raw Permalink Normal View History

2023-12-13 17:59:14 +08:00
package utils
2023-12-13 10:59:47 +08:00
import (
"path/filepath"
"testing"
)
func TestNormalizePath(t *testing.T) {
tests := []struct {
name string
path string
want string
}{
{
name: "Test case 1",
path: "/path/to/file",
want: "/path/to/file",
},
{
name: "Test case 2",
path: "path/to/file",
want: GetExecDir() + "/path/to/file",
},
{
name: "Test case 3",
path: "../path/to/file",
want: filepath.Join(GetExecDir(), "../path/to/file"),
},
{
name: "Test case 4",
path: "./path/to/file",
want: GetExecDir() + "/path/to/file",
},
{
name: "Test case 5",
path: "/absolute/path/to/file",
want: "/absolute/path/to/file",
},
{
name: "Test case 6",
path: "relative/path/to/file",
want: GetExecDir() + "/relative/path/to/file",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NormalizePath(tt.path); got != tt.want {
t.Errorf("NormalizePath() = %v, want %v", got, tt.want)
}
})
}
}