This checks for the equivalent WSL mount path on windows. WSL will mount the windows drives at `/mnt/c` (or whichever drive is being used). This is done by parsing a UNC path with forward slashes from the unix socket URL. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
30 lines
586 B
Go
30 lines
586 B
Go
package command
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
"testing/fstest"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestWslSocketPath(t *testing.T) {
|
|
u, err := url.Parse("unix:////./c:/my/file/path")
|
|
assert.NilError(t, err)
|
|
|
|
// Ensure host is empty.
|
|
assert.Equal(t, u.Host, "")
|
|
|
|
// Use a filesystem where the WSL path exists.
|
|
fs := fstest.MapFS{
|
|
"mnt/c/my/file/path": {},
|
|
}
|
|
assert.Equal(t, wslSocketPath(u.Path, fs), "/mnt/c/my/file/path")
|
|
|
|
// Use a filesystem where the WSL path doesn't exist.
|
|
fs = fstest.MapFS{
|
|
"my/file/path": {},
|
|
}
|
|
assert.Equal(t, wslSocketPath(u.Path, fs), "")
|
|
}
|