aboutsummaryrefslogtreecommitdiffstats
path: root/browserenv_unix_test.go
diff options
context:
space:
mode:
authorTeddy Wing2020-12-20 02:43:20 +0100
committerTeddy Wing2020-12-20 02:43:39 +0100
commit3dca44be5342384334020c8f64752caaf86d334d (patch)
treeed03d3d71772f7b95c92b1fb2e8ff6756eaea315 /browserenv_unix_test.go
parent7df3fe207889331998a26e386c1b65332b279b95 (diff)
downloadbrowserenv-3dca44be5342384334020c8f64752caaf86d334d.tar.bz2
TestBrowserCommand: Convert to table-driven test
So we can add other test cases.
Diffstat (limited to 'browserenv_unix_test.go')
-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)
+ }
+ })
}
}