2024-09-12 12:14:43 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2024-09-17 11:51:30 -04:00
|
|
|
"io/fs"
|
2024-09-12 12:14:43 -04:00
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
"testing/fstest"
|
|
|
|
|
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWslSocketPath(t *testing.T) {
|
2024-09-17 11:51:30 -04:00
|
|
|
testCases := []struct {
|
|
|
|
doc string
|
|
|
|
fs fs.FS
|
|
|
|
url string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
doc: "filesystem where WSL path does not exist",
|
|
|
|
fs: fstest.MapFS{
|
|
|
|
"my/file/path": {},
|
|
|
|
},
|
|
|
|
url: "unix:////./c:/my/file/path",
|
|
|
|
expected: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
doc: "filesystem where WSL path exists",
|
|
|
|
fs: fstest.MapFS{
|
|
|
|
"mnt/c/my/file/path": {},
|
|
|
|
},
|
|
|
|
url: "unix:////./c:/my/file/path",
|
|
|
|
expected: "/mnt/c/my/file/path",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
doc: "filesystem where WSL path exists uppercase URL",
|
|
|
|
fs: fstest.MapFS{
|
|
|
|
"mnt/c/my/file/path": {},
|
|
|
|
},
|
|
|
|
url: "unix:////./C:/my/file/path",
|
|
|
|
expected: "/mnt/c/my/file/path",
|
|
|
|
},
|
|
|
|
}
|
2024-09-12 12:14:43 -04:00
|
|
|
|
2024-09-17 11:51:30 -04:00
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.doc, func(t *testing.T) {
|
|
|
|
u, err := url.Parse(tc.url)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
// Ensure host is empty.
|
|
|
|
assert.Equal(t, u.Host, "")
|
2024-09-12 12:14:43 -04:00
|
|
|
|
2024-09-17 11:51:30 -04:00
|
|
|
result := wslSocketPath(u.Path, tc.fs)
|
2024-09-12 12:14:43 -04:00
|
|
|
|
2024-09-17 11:51:30 -04:00
|
|
|
assert.Equal(t, result, tc.expected)
|
|
|
|
})
|
2024-09-12 12:14:43 -04:00
|
|
|
}
|
|
|
|
}
|