summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorFrancisco Miamoto <fsmiamoto@gmail.com>2021-05-31 21:06:59 -0300
committerJesse Duffield <jessedduffield@gmail.com>2021-07-27 20:28:00 +1000
commitf8f596d097942d0a0e0cd0ab76e48ec1c2471d75 (patch)
treedb13fefc57ea16ec7e3c58495151550fcf4102c5 /pkg/commands
parent028cb2be2f844b6563ac906e8066df184753fa8c (diff)
add tests for open file cmd on linux
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/oscommands/os_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go
index 5be52683e..2f015c21c 100644
--- a/pkg/commands/oscommands/os_test.go
+++ b/pkg/commands/oscommands/os_test.go
@@ -103,6 +103,7 @@ func TestOSCommandOpenFile(t *testing.T) {
for _, s := range scenarios {
OSCmd := NewDummyOSCommand()
+ OSCmd.Platform.OS = "darwin"
OSCmd.Command = s.command
OSCmd.Config.GetUserConfig().OS.OpenCommand = "open {{filename}}"
@@ -110,6 +111,80 @@ func TestOSCommandOpenFile(t *testing.T) {
}
}
+// TestOSCommandOpenFile tests the OpenFile command on Linux
+func TestOSCommandOpenFileLinux(t *testing.T) {
+ type scenario struct {
+ filename string
+ command func(string, ...string) *exec.Cmd
+ test func(error)
+ }
+
+ scenarios := []scenario{
+ {
+ "test",
+ func(name string, arg ...string) *exec.Cmd {
+ return secureexec.Command("exit", "1")
+ },
+ func(err error) {
+ assert.Error(t, err)
+ },
+ },
+ {
+ "test",
+ func(name string, arg ...string) *exec.Cmd {
+ assert.Equal(t, "sh", name)
+ assert.Equal(t, []string{"-c", "xdg-open \"test\" > /dev/null"}, arg)
+ return secureexec.Command("echo")
+ },
+ func(err error) {
+ assert.NoError(t, err)
+ },
+ },
+ {
+ "filename with spaces",
+ func(name string, arg ...string) *exec.Cmd {
+ assert.Equal(t, "sh", name)
+ assert.Equal(t, []string{"-c", "xdg-open \"filename with spaces\" > /dev/null"}, arg)
+ return secureexec.Command("echo")
+ },
+ func(err error) {
+ assert.NoError(t, err)
+ },
+ },
+ {
+ "let's_test_with_single_quote",
+ func(name string, arg ...string) *exec.Cmd {
+ assert.Equal(t, "sh", name)
+ assert.Equal(t, []string{"-c", "xdg-open \"let's_test_with_single_quote\" > /dev/null"}, arg)
+ return secureexec.Command("echo")
+ },
+ func(err error) {
+ assert.NoError(t, err)
+ },
+ },
+ {
+ "$USER.txt",
+ func(name string, arg ...string) *exec.Cmd {
+ assert.Equal(t, "sh", name)
+ assert.Equal(t, []string{"-c", "xdg-open \"\\$USER.txt\" > /dev/null"}, arg)
+ return secureexec.Command("echo")
+ },
+ func(err error) {
+ assert.NoError(t, err)
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ OSCmd := NewDummyOSCommand()
+ OSCmd.Command = s.command
+ OSCmd.Platform.OS = "linux"
+ OSCmd.Config.GetUserConfig().OS.OpenCommand = `sh -c "xdg-open {{filename}} > /dev/null"`
+
+ s.test(OSCmd.OpenFile(s.filename))
+ }
+}
+
// TestOSCommandQuote is a function.
func TestOSCommandQuote(t *testing.T) {
osCommand := NewDummyOSCommand()