From ba0cc20e228df324530f3ac6075a591dbae35bb9 Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Mon, 10 Sep 2018 06:51:19 +0200 Subject: feat: add test cases --- pkg/commands/os.go | 2 ++ pkg/commands/os_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'pkg/commands') diff --git a/pkg/commands/os.go b/pkg/commands/os.go index fd77f21c7..af0c1be8b 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -2,6 +2,7 @@ package commands import ( "errors" + "fmt" "os" "os/exec" "strings" @@ -139,6 +140,7 @@ func (c *OSCommand) PrepareSubProcess(cmdName string, commandArgs ...string) *ex // Quote wraps a message in platform-specific quotation marks func (c *OSCommand) Quote(message string) string { + fmt.Println(c.Platform.os) message = strings.Replace(message, "`", "\\`", -1) if c.Platform.os == "linux" { if strings.ContainsRune(message, '\'') { diff --git a/pkg/commands/os_test.go b/pkg/commands/os_test.go index 01173fb15..456c54e04 100644 --- a/pkg/commands/os_test.go +++ b/pkg/commands/os_test.go @@ -265,6 +265,30 @@ func TestOSCommandQuote(t *testing.T) { assert.EqualValues(t, expected, actual) } +func TestOSCommandQuoteSingleQuote(t *testing.T) { + osCommand := newDummyOSCommand() + + osCommand.Platform.os = "linux" + + actual := osCommand.Quote("hello 'test'") + + expected := osCommand.Platform.escapedQuote + "hello 'test'" + osCommand.Platform.escapedQuote + + assert.EqualValues(t, expected, actual) +} + +func TestOSCommandQuoteDoubleQuote(t *testing.T) { + osCommand := newDummyOSCommand() + + osCommand.Platform.os = "linux" + + actual := osCommand.Quote(`hello "test"`) + + expected := osCommand.Platform.escapedQuote + "hello \"test\"" + osCommand.Platform.escapedQuote + + assert.EqualValues(t, expected, actual) +} + func TestOSCommandUnquote(t *testing.T) { osCommand := newDummyOSCommand() -- cgit v1.2.3