1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-17 00:18:05 +02:00

add tests to pkg/commands

This commit is contained in:
Anthony HAMON
2018-08-21 23:17:44 +02:00
parent 364c1ac5e7
commit f91e2b12db

View File

@ -1,16 +1,76 @@
package commands package commands
import "testing" import (
"testing"
func TestQuote(t *testing.T) { "github.com/Sirupsen/logrus"
osCommand := &OSCommand{
Log: nil, "github.com/stretchr/testify/assert"
Platform: getPlatform(), )
func TestRunCommandWithOutput(t *testing.T) {
type scenario struct {
command string
test func(string, error)
} }
test := "hello `test`"
expected := osCommand.Platform.escapedQuote + "hello \\`test\\`" + osCommand.Platform.escapedQuote scenarios := []scenario{
test = osCommand.Quote(test) {
if test != expected { "echo -n '123'",
t.Error("Expected " + expected + ", got " + test) 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))
}
}
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)
}