1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-26 09:00:57 +02:00
lazygit/pkg/commands/os_test.go

79 lines
1.5 KiB
Go
Raw Normal View History

package commands
2018-08-21 23:17:44 +02:00
import (
"testing"
2018-08-21 23:17:44 +02:00
"github.com/stretchr/testify/assert"
)
2018-08-22 22:30:02 +02:00
func newDummyOSCommand() *OSCommand {
return NewOSCommand(newDummyLog())
}
func TestOSCommandRunCommandWithOutput(t *testing.T) {
2018-08-21 23:17:44 +02:00
type scenario struct {
command string
test func(string, error)
}
2018-08-21 23:17:44 +02:00
scenarios := []scenario{
{
"echo -n '123'",
func(output string, err error) {
assert.NoError(t, err)
assert.EqualValues(t, "123", output)
},
},
{
"rmdir unexisting-folder",
func(output string, err error) {
assert.Regexp(t, ".*No such file or directory.*", err.Error())
},
},
}
for _, s := range scenarios {
2018-08-22 22:30:02 +02:00
s.test(newDummyOSCommand().RunCommandWithOutput(s.command))
2018-08-21 23:17:44 +02:00
}
}
2018-08-22 22:30:02 +02:00
func TestOSCommandRunCommand(t *testing.T) {
2018-08-21 23:17:44 +02:00
type scenario struct {
command string
test func(error)
}
scenarios := []scenario{
{
"rmdir unexisting-folder",
func(err error) {
assert.Regexp(t, ".*No such file or directory.*", err.Error())
},
},
}
for _, s := range scenarios {
2018-08-22 22:30:02 +02:00
s.test(newDummyOSCommand().RunCommand(s.command))
}
}
2018-08-21 23:17:44 +02:00
2018-08-22 22:30:02 +02:00
func TestOSCommandQuote(t *testing.T) {
osCommand := newDummyOSCommand()
2018-08-21 23:17:44 +02:00
actual := osCommand.Quote("hello `test`")
expected := osCommand.Platform.escapedQuote + "hello \\`test\\`" + osCommand.Platform.escapedQuote
assert.EqualValues(t, expected, actual)
}
2018-08-22 22:30:02 +02:00
func TestOSCommandUnquote(t *testing.T) {
osCommand := newDummyOSCommand()
2018-08-21 23:17:44 +02:00
actual := osCommand.Unquote(`hello "test"`)
expected := "hello test"
assert.EqualValues(t, expected, actual)
}