-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_wsl_test.go
More file actions
69 lines (65 loc) · 1.27 KB
/
main_wsl_test.go
File metadata and controls
69 lines (65 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"testing"
)
func TestDetectWSL(t *testing.T) {
tests := []struct {
name string
goos string
env map[string]string
osrelease string
readErr error
want bool
}{
{
name: "windows process in wsl via env",
goos: "windows",
env: map[string]string{
"WSL_INTEROP": "1",
},
want: true,
},
{
name: "linux wsl via osrelease",
goos: "linux",
osrelease: "5.15.153.1-microsoft-standard-WSL2",
want: true,
},
{
name: "linux non wsl",
goos: "linux",
osrelease: "6.8.0-48-generic",
want: false,
},
{
name: "linux osrelease unavailable",
goos: "linux",
readErr: errors.New("read error"),
want: false,
},
{
name: "windows non wsl",
goos: "windows",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lookup := func(key string) (string, bool) {
v, ok := tt.env[key]
return v, ok
}
read := func(path string) ([]byte, error) {
if tt.readErr != nil {
return nil, tt.readErr
}
return []byte(tt.osrelease), nil
}
got := detectWSL(tt.goos, lookup, read)
if got != tt.want {
t.Fatalf("detectWSL(%q) = %v, want %v", tt.goos, got, tt.want)
}
})
}
}