Files
sherlock/internal/browser/browser_test.go
T
Alexandru Macocian f6e8186b46
Release / release (push) Successful in 26s
Support for custom browser
2026-06-15 17:19:22 +02:00

37 lines
1.1 KiB
Go

package browser
import (
"reflect"
"testing"
)
func TestCommandFor_Defaults(t *testing.T) {
tests := []struct {
name string
goos string
wantBin string
wantArgs []string
}{
{name: "linux", goos: "linux", wantBin: "xdg-open", wantArgs: []string{"https://example.com"}},
{name: "darwin", goos: "darwin", wantBin: "open", wantArgs: []string{"https://example.com"}},
{name: "windows", goos: "windows", wantBin: "rundll32", wantArgs: []string{"url.dll,FileProtocolHandler", "https://example.com"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotBin, gotArgs := commandFor("", "https://example.com", tt.goos)
if gotBin != tt.wantBin || !reflect.DeepEqual(gotArgs, tt.wantArgs) {
t.Fatalf("commandFor = %q %v, want %q %v", gotBin, gotArgs, tt.wantBin, tt.wantArgs)
}
})
}
}
func TestCommandFor_CustomBrowser(t *testing.T) {
gotBin, gotArgs := commandFor(" firefox ", "https://example.com", "linux")
wantArgs := []string{"https://example.com"}
if gotBin != "firefox" || !reflect.DeepEqual(gotArgs, wantArgs) {
t.Fatalf("commandFor = %q %v, want firefox %v", gotBin, gotArgs, wantArgs)
}
}