11package command
22
33import (
4+ "io/fs"
45 "net/url"
56 "testing"
67 "testing/fstest"
@@ -9,21 +10,48 @@ import (
910)
1011
1112func TestWslSocketPath (t * testing.T ) {
12- u , err := url .Parse ("unix:////./c:/my/file/path" )
13- assert .NilError (t , err )
13+ testCases := []struct {
14+ doc string
15+ fs fs.FS
16+ url string
17+ expected string
18+ }{
19+ {
20+ doc : "filesystem where WSL path does not exist" ,
21+ fs : fstest.MapFS {
22+ "my/file/path" : {},
23+ },
24+ url : "unix:////./c:/my/file/path" ,
25+ expected : "" ,
26+ },
27+ {
28+ doc : "filesystem where WSL path exists" ,
29+ fs : fstest.MapFS {
30+ "mnt/c/my/file/path" : {},
31+ },
32+ url : "unix:////./c:/my/file/path" ,
33+ expected : "/mnt/c/my/file/path" ,
34+ },
35+ {
36+ doc : "filesystem where WSL path exists uppercase URL" ,
37+ fs : fstest.MapFS {
38+ "mnt/c/my/file/path" : {},
39+ },
40+ url : "unix:////./C:/my/file/path" ,
41+ expected : "/mnt/c/my/file/path" ,
42+ },
43+ }
1444
15- // Ensure host is empty.
16- assert .Equal (t , u .Host , "" )
45+ for _ , tc := range testCases {
46+ t .Run (tc .doc , func (t * testing.T ) {
47+ u , err := url .Parse (tc .url )
48+ assert .NilError (t , err )
49+ // Ensure host is empty.
50+ assert .Equal (t , u .Host , "" )
1751
18- // Use a filesystem where the WSL path exists.
19- fs := fstest.MapFS {
20- "mnt/c/my/file/path" : {},
21- }
22- assert .Equal (t , wslSocketPath (u .Path , fs ), "/mnt/c/my/file/path" )
52+ result := wslSocketPath (u .Path , tc .fs )
2353
24- // Use a filesystem where the WSL path doesn't exist.
25- fs = fstest.MapFS {
26- "my/file/path" : {},
54+ assert .Equal (t , result , tc .expected )
55+ })
2756 }
28- assert .Equal (t , wslSocketPath (u .Path , fs ), "" )
2957}
0 commit comments