1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-05 15:15:49 +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
import "testing"
import (
"testing"
func TestQuote(t *testing.T) {
osCommand := &OSCommand{
Log: nil,
Platform: getPlatform(),
"github.com/Sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
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
test = osCommand.Quote(test)
if test != expected {
t.Error("Expected " + expected + ", got " + test)
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))
}
}
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)
}