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

77 lines
1.4 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/Sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
func TestRunCommandWithOutput(t *testing.T) {
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 {
s.test(NewOSCommand(logrus.New()).RunCommandWithOutput(s.command))
}
}
func TestRunCommand(t *testing.T) {
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 {
s.test(NewOSCommand(logrus.New()).RunCommand(s.command))
}
}
2018-08-21 23:17:44 +02:00
func TestQuote(t *testing.T) {
osCommand := NewOSCommand(logrus.New())
actual := osCommand.Quote("hello `test`")
expected := osCommand.Platform.escapedQuote + "hello \\`test\\`" + osCommand.Platform.escapedQuote
assert.EqualValues(t, expected, actual)
}
func TestUnquote(t *testing.T) {
osCommand := NewOSCommand(logrus.New())
actual := osCommand.Unquote(`hello "test"`)
expected := "hello test"
assert.EqualValues(t, expected, actual)
}