Skip to content

Commit

Permalink
Merge pull request #5449 from laurazard/backport-lowercase-windows-drive
Browse files Browse the repository at this point in the history
[27.x backport] command: change drive to lowercase for wsl path
  • Loading branch information
thaJeztah authored Sep 18, 2024
2 parents fcf6dd0 + c6dde25 commit ddf8f23
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cli/command/telemetry_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func toWslPath(s string) string {
if !ok {
return ""
}
return fmt.Sprintf("mnt/%s%s", drive, p)
return fmt.Sprintf("mnt/%s%s", strings.ToLower(drive), p)
}

func parseUNCPath(s string) (drive, p string, ok bool) {
Expand Down
54 changes: 41 additions & 13 deletions cli/command/telemetry_docker_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"io/fs"
"net/url"
"testing"
"testing/fstest"
Expand All @@ -9,21 +10,48 @@ import (
)

func TestWslSocketPath(t *testing.T) {
u, err := url.Parse("unix:////./c:/my/file/path")
assert.NilError(t, err)
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",
},
}

// Ensure host is empty.
assert.Equal(t, u.Host, "")
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, "")

// 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")
result := wslSocketPath(u.Path, tc.fs)

// Use a filesystem where the WSL path doesn't exist.
fs = fstest.MapFS{
"my/file/path": {},
assert.Equal(t, result, tc.expected)
})
}
assert.Equal(t, wslSocketPath(u.Path, fs), "")
}

0 comments on commit ddf8f23

Please sign in to comment.