forked from jesseduffield/lazygit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable/disable os specific tests at compile time
- Loading branch information
1 parent
1e50764
commit 7564e50
Showing
6 changed files
with
740 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package oscommands | ||
|
||
import ( | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/jesseduffield/lazygit/pkg/secureexec" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestOSCommandOpenFileDarwin is a function. | ||
func TestOSCommandOpenFileDarwin(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, "bash", name) | ||
assert.Equal(t, []string{"-c", `open "test"`}, 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, "bash", name) | ||
assert.Equal(t, []string{"-c", `open "filename with spaces"`}, arg) | ||
return secureexec.Command("echo") | ||
}, | ||
func(err error) { | ||
assert.NoError(t, err) | ||
}, | ||
}, | ||
} | ||
|
||
for _, s := range scenarios { | ||
OSCmd := NewDummyOSCommand() | ||
OSCmd.Platform.OS = "darwin" | ||
OSCmd.Command = s.command | ||
OSCmd.Config.GetUserConfig().OS.OpenCommand = "open {{filename}}" | ||
|
||
s.test(OSCmd.OpenFile(s.filename)) | ||
} | ||
} | ||
|
||
// TestOSCommandOpenFileLinux 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, "bash", 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, "bash", 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, "bash", 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, "bash", 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 = `xdg-open {{filename}} > /dev/null` | ||
|
||
s.test(OSCmd.OpenFile(s.filename)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.