forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser_test.go
More file actions
75 lines (72 loc) · 1.44 KB
/
browser_test.go
File metadata and controls
75 lines (72 loc) · 1.44 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
70
71
72
73
74
75
package browser
import (
"errors"
"reflect"
"testing"
)
func TestForOS(t *testing.T) {
type args struct {
goos string
url string
}
tests := []struct {
name string
args args
exe string
want []string
}{
{
name: "macOS",
args: args{
goos: "darwin",
url: "https://example.com/path?a=1&b=2",
},
want: []string{"open", "https://example.com/path?a=1&b=2"},
},
{
name: "Linux",
args: args{
goos: "linux",
url: "https://example.com/path?a=1&b=2",
},
exe: "xdg-open",
want: []string{"xdg-open", "https://example.com/path?a=1&b=2"},
},
{
name: "WSL",
args: args{
goos: "linux",
url: "https://example.com/path?a=1&b=2",
},
exe: "wslview",
want: []string{"wslview", "https://example.com/path?a=1&b=2"},
},
{
name: "Windows",
args: args{
goos: "windows",
url: "https://example.com/path?a=1&b=2&c=3",
},
exe: "cmd",
want: []string{"cmd", "/c", "start", "https://example.com/path?a=1^&b=2^&c=3"},
},
}
for _, tt := range tests {
origLookPath := lookPath
lookPath = func(file string) (string, error) {
if file == tt.exe {
return file, nil
} else {
return "", errors.New("not found")
}
}
defer func() {
lookPath = origLookPath
}()
t.Run(tt.name, func(t *testing.T) {
if cmd := ForOS(tt.args.goos, tt.args.url); !reflect.DeepEqual(cmd.Args, tt.want) {
t.Errorf("ForOS() = %v, want %v", cmd.Args, tt.want)
}
})
}
}