aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--browserenv_unix_test.go38
1 files changed, 25 insertions, 13 deletions
diff --git a/browserenv_unix_test.go b/browserenv_unix_test.go
index bcc7c2d..35af81c 100644
--- a/browserenv_unix_test.go
+++ b/browserenv_unix_test.go
@@ -3,27 +3,39 @@
package browserenv
import (
- "fmt"
"os"
"reflect"
"testing"
)
func TestBrowserCommand(t *testing.T) {
- envValue := "open -a Firefox"
- url := "https://duckduckgo.com"
-
- cmd := browserCommand(envValue, url)
-
- shell := os.Getenv("SHELL")
- if shell == "" {
- shell = "/bin/sh"
+ tests := []struct {
+ name string
+ envValue string
+ url string
+ wantCmd string
+ }{
+ {
+ "without URL directive",
+ "open -a Firefox",
+ "https://duckduckgo.com",
+ "open -a Firefox 'https://duckduckgo.com'",
+ },
}
- browserCommand := fmt.Sprintf("%s '%s'", envValue, url)
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ cmd := browserCommand(test.envValue, test.url)
+
+ shell := os.Getenv("SHELL")
+ if shell == "" {
+ shell = "/bin/sh"
+ }
- wantArgs := []string{shell, "-c", browserCommand}
- if !reflect.DeepEqual(cmd.Args, wantArgs) {
- t.Errorf("got args '%#v' want '%#v'", cmd.Args, wantArgs)
+ wantArgs := []string{shell, "-c", test.wantCmd}
+ if !reflect.DeepEqual(cmd.Args, wantArgs) {
+ t.Errorf("got args '%#v' want '%#v'", cmd.Args, wantArgs)
+ }
+ })
}
}