mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-28 23:18:15 +00:00
feat: add portability to command invocation unit tests (#3758)
* Add portability to command invocation unit tests * Fix linting
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package runtime_test
|
package runtime_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -18,6 +19,8 @@ func TestPostWorkflowHookRunner_Run(t *testing.T) {
|
|||||||
|
|
||||||
defaultShell := "sh"
|
defaultShell := "sh"
|
||||||
defaultShellArgs := "-c"
|
defaultShellArgs := "-c"
|
||||||
|
defautShellCommandNotFoundErrorFormat := commandNotFoundErrorFormat(defaultShell)
|
||||||
|
defaultUnterminatedStringError := unterminatedStringError(defaultShell, defaultShellArgs)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Command string
|
Command string
|
||||||
@@ -63,7 +66,7 @@ func TestPostWorkflowHookRunner_Run(t *testing.T) {
|
|||||||
Command: "echo 'a",
|
Command: "echo 'a",
|
||||||
Shell: defaultShell,
|
Shell: defaultShell,
|
||||||
ShellArgs: defaultShellArgs,
|
ShellArgs: defaultShellArgs,
|
||||||
ExpOut: "sh: 1: Syntax error: Unterminated quoted string\r\n",
|
ExpOut: defaultUnterminatedStringError,
|
||||||
ExpErr: "exit status 2: running \"sh -c echo 'a\" in",
|
ExpErr: "exit status 2: running \"sh -c echo 'a\" in",
|
||||||
ExpDescription: "",
|
ExpDescription: "",
|
||||||
},
|
},
|
||||||
@@ -79,7 +82,7 @@ func TestPostWorkflowHookRunner_Run(t *testing.T) {
|
|||||||
Command: "lkjlkj",
|
Command: "lkjlkj",
|
||||||
Shell: defaultShell,
|
Shell: defaultShell,
|
||||||
ShellArgs: defaultShellArgs,
|
ShellArgs: defaultShellArgs,
|
||||||
ExpOut: "sh: 1: lkjlkj: not found\r\n",
|
ExpOut: fmt.Sprintf(defautShellCommandNotFoundErrorFormat, "lkjlkj"),
|
||||||
ExpErr: "exit status 127: running \"sh -c lkjlkj\" in",
|
ExpErr: "exit status 127: running \"sh -c lkjlkj\" in",
|
||||||
ExpDescription: "",
|
ExpDescription: "",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package runtime_test
|
package runtime_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
goruntime "runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -14,10 +16,31 @@ import (
|
|||||||
. "github.com/runatlantis/atlantis/testing"
|
. "github.com/runatlantis/atlantis/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func commandNotFoundErrorFormat(shell string) string {
|
||||||
|
// TODO: Add more GOOSs. Also I haven't done too much testing
|
||||||
|
// maybe the output here depends on other factors as well
|
||||||
|
if goruntime.GOOS == "darwin" {
|
||||||
|
return fmt.Sprintf("%s: %%s: command not found\r\n", shell)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s: 1: %%s: not found\r\n", shell)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func unterminatedStringError(shell, shellArgs string) string {
|
||||||
|
// TODO: Add more GOOSs. Also I haven't done too much testing
|
||||||
|
// maybe the output here depends on other factors as well
|
||||||
|
if goruntime.GOOS == "darwin" {
|
||||||
|
return fmt.Sprintf("%s: %s: line 0: unexpected EOF while looking for matching `''\r\n%s: %s: line 1: syntax error: unexpected end of file\r\n", shell, shellArgs, shell, shellArgs)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s: 1: Syntax error: Unterminated quoted string\r\n", shell)
|
||||||
|
}
|
||||||
|
|
||||||
func TestPreWorkflowHookRunner_Run(t *testing.T) {
|
func TestPreWorkflowHookRunner_Run(t *testing.T) {
|
||||||
|
|
||||||
defaultShell := "sh"
|
defaultShell := "sh"
|
||||||
defaultShellArgs := "-c"
|
defaultShellArgs := "-c"
|
||||||
|
defautShellCommandNotFoundErrorFormat := commandNotFoundErrorFormat(defaultShell)
|
||||||
|
defaultUnterminatedStringError := unterminatedStringError(defaultShell, defaultShellArgs)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Command string
|
Command string
|
||||||
@@ -63,7 +86,7 @@ func TestPreWorkflowHookRunner_Run(t *testing.T) {
|
|||||||
Command: "echo 'a",
|
Command: "echo 'a",
|
||||||
Shell: defaultShell,
|
Shell: defaultShell,
|
||||||
ShellArgs: defaultShellArgs,
|
ShellArgs: defaultShellArgs,
|
||||||
ExpOut: "sh: 1: Syntax error: Unterminated quoted string\r\n",
|
ExpOut: defaultUnterminatedStringError,
|
||||||
ExpErr: "exit status 2: running \"sh -c echo 'a\" in",
|
ExpErr: "exit status 2: running \"sh -c echo 'a\" in",
|
||||||
ExpDescription: "",
|
ExpDescription: "",
|
||||||
},
|
},
|
||||||
@@ -79,7 +102,7 @@ func TestPreWorkflowHookRunner_Run(t *testing.T) {
|
|||||||
Command: "lkjlkj",
|
Command: "lkjlkj",
|
||||||
Shell: defaultShell,
|
Shell: defaultShell,
|
||||||
ShellArgs: defaultShellArgs,
|
ShellArgs: defaultShellArgs,
|
||||||
ExpOut: "sh: 1: lkjlkj: not found\r\n",
|
ExpOut: fmt.Sprintf(defautShellCommandNotFoundErrorFormat, "lkjlkj"),
|
||||||
ExpErr: "exit status 127: running \"sh -c lkjlkj\" in",
|
ExpErr: "exit status 127: running \"sh -c lkjlkj\" in",
|
||||||
ExpDescription: "",
|
ExpDescription: "",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user