|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package commands
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
@ -153,13 +154,14 @@ func TestOSCommandEditFile(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestOSCommandQuote is a function.
|
|
|
|
|
func TestOSCommandQuote(t *testing.T) {
|
|
|
|
|
osCommand := NewDummyOSCommand()
|
|
|
|
|
|
|
|
|
|
osCommand.Platform.os = "linux"
|
|
|
|
|
|
|
|
|
|
actual := osCommand.Quote("hello `test`")
|
|
|
|
|
|
|
|
|
|
expected := osCommand.Platform.escapedQuote + "hello \\`test\\`" + osCommand.Platform.escapedQuote
|
|
|
|
|
expected := "\"hello \\`test\\`\""
|
|
|
|
|
|
|
|
|
|
assert.EqualValues(t, expected, actual)
|
|
|
|
|
}
|
|
|
|
@ -169,12 +171,10 @@ func TestOSCommandQuoteSingleQuote(t *testing.T) {
|
|
|
|
|
osCommand := NewDummyOSCommand()
|
|
|
|
|
|
|
|
|
|
osCommand.Platform.os = "linux"
|
|
|
|
|
osCommand.Platform.fallbackEscapedQuote = "\""
|
|
|
|
|
osCommand.Platform.escapedQuote = "'"
|
|
|
|
|
|
|
|
|
|
actual := osCommand.Quote("hello 'test'")
|
|
|
|
|
|
|
|
|
|
expected := osCommand.Platform.fallbackEscapedQuote + "hello 'test'" + osCommand.Platform.fallbackEscapedQuote
|
|
|
|
|
expected := `"hello 'test'"`
|
|
|
|
|
|
|
|
|
|
assert.EqualValues(t, expected, actual)
|
|
|
|
|
}
|
|
|
|
@ -187,7 +187,20 @@ func TestOSCommandQuoteDoubleQuote(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
actual := osCommand.Quote(`hello "test"`)
|
|
|
|
|
|
|
|
|
|
expected := osCommand.Platform.escapedQuote + "hello \"test\"" + osCommand.Platform.escapedQuote
|
|
|
|
|
expected := `"hello \"test\""`
|
|
|
|
|
|
|
|
|
|
assert.EqualValues(t, expected, actual)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestOSCommandQuoteWindows tests the quote function for Windows
|
|
|
|
|
func TestOSCommandQuoteWindows(t *testing.T) {
|
|
|
|
|
osCommand := NewDummyOSCommand()
|
|
|
|
|
|
|
|
|
|
osCommand.Platform.os = "windows"
|
|
|
|
|
|
|
|
|
|
actual := osCommand.Quote(`hello "test" 'test2'`)
|
|
|
|
|
|
|
|
|
|
expected := `\"hello "'"'"test"'"'" 'test2'\"`
|
|
|
|
|
|
|
|
|
|
assert.EqualValues(t, expected, actual)
|
|
|
|
|
}
|
|
|
|
@ -291,3 +304,53 @@ func TestOSCommandCreateTempFile(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestOSCommandExecutableFromStringWithShellLinux(t *testing.T) {
|
|
|
|
|
osCommand := NewDummyOSCommand()
|
|
|
|
|
|
|
|
|
|
osCommand.Platform.os = "linux"
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
commandStr string
|
|
|
|
|
want string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
"success",
|
|
|
|
|
"pwd",
|
|
|
|
|
fmt.Sprintf("%v %v %v", osCommand.Platform.shell, osCommand.Platform.shellArg, "\"pwd\""),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
got := osCommand.NewCommandStringWithShell(tt.commandStr)
|
|
|
|
|
assert.Equal(t, tt.want, got)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestOSCommandNewCommandStringWithShellWindows(t *testing.T) {
|
|
|
|
|
osCommand := NewDummyOSCommand()
|
|
|
|
|
|
|
|
|
|
osCommand.Platform.os = "windows"
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
commandStr string
|
|
|
|
|
want string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
"success",
|
|
|
|
|
"pwd",
|
|
|
|
|
fmt.Sprintf("%v %v %v", osCommand.Platform.shell, osCommand.Platform.shellArg, "pwd"),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
got := osCommand.NewCommandStringWithShell(tt.commandStr)
|
|
|
|
|
assert.Equal(t, tt.want, got)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|