aboutsummaryrefslogtreecommitdiffstats
path: root/browserenv_unix_test.go
blob: 35af81ca513b739e65e3d59790ecc9e253cc7a52 (plain)
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
// +build !windows

package browserenv

import (
	"os"
	"reflect"
	"testing"
)

func TestBrowserCommand(t *testing.T) {
	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'",
		},
	}

	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", test.wantCmd}
			if !reflect.DeepEqual(cmd.Args, wantArgs) {
				t.Errorf("got args '%#v' want '%#v'", cmd.Args, wantArgs)
			}
		})
	}
}