-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser_test.go
More file actions
57 lines (54 loc) · 1.32 KB
/
browser_test.go
File metadata and controls
57 lines (54 loc) · 1.32 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
package main
import "testing"
func TestBrowserCommand(t *testing.T) {
tests := []struct {
goos string
url string
wantName string
wantArgs []string
}{
{
goos: "darwin",
url: "https://example.com/auth",
wantName: "open",
wantArgs: []string{"https://example.com/auth"},
},
{
goos: "windows",
url: "https://example.com/auth",
wantName: "rundll32",
wantArgs: []string{"url.dll,FileProtocolHandler", "https://example.com/auth"},
},
{
goos: "linux",
url: "https://example.com/auth",
wantName: "xdg-open",
wantArgs: []string{"https://example.com/auth"},
},
{
goos: "windows",
url: "https://example.com/auth?foo=bar&baz=qux",
wantName: "rundll32",
wantArgs: []string{
"url.dll,FileProtocolHandler",
"https://example.com/auth?foo=bar&baz=qux",
},
},
}
for _, tt := range tests {
t.Run(tt.goos, func(t *testing.T) {
name, args := browserCommand(tt.goos, tt.url)
if name != tt.wantName {
t.Errorf("name: got %q, want %q", name, tt.wantName)
}
if len(args) != len(tt.wantArgs) {
t.Fatalf("args length: got %d, want %d", len(args), len(tt.wantArgs))
}
for i, arg := range args {
if arg != tt.wantArgs[i] {
t.Errorf("args[%d]: got %q, want %q", i, arg, tt.wantArgs[i])
}
}
})
}
}