1
1
package command
2
2
3
3
import (
4
+ "io/fs"
4
5
"net/url"
5
6
"testing"
6
7
"testing/fstest"
@@ -9,21 +10,48 @@ import (
9
10
)
10
11
11
12
func 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
+ }
14
44
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 , "" )
17
51
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 )
23
53
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
+ })
27
56
}
28
- assert .Equal (t , wslSocketPath (u .Path , fs ), "" )
29
57
}
0 commit comments