Merge pull request #52 from yxxhero/feat_inherit_environment_variables_for_Exec

add unittest for Exec
This commit is contained in:
Yusuke Kuoka 2022-04-22 12:21:31 +09:00 committed by GitHub
commit 1bcf6a7bb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -252,3 +252,18 @@ func TestRequiredEnv(t *testing.T) {
require.Equalf(t, expected, envVal, "Expected %s to be returned when environment variable %s is set to a non-empty string", expected, envKey) require.Equalf(t, expected, envVal, "Expected %s to be returned when environment variable %s is set to a non-empty string", expected, envKey)
} }
// TestExec tests that Exec returns the expected output.
func TestExec(t *testing.T) {
ctx := &Context{basePath: "."}
// test that the command is executed
expected := "foo\n"
output, err := ctx.Exec("echo", []interface{}{"foo"}, "")
require.Nilf(t, err, "Expected no error to be returned when executing command")
require.Equalf(t, expected, output, "Expected %s to be returned when executing command", expected)
// test that the command is executed with no-zero exit code
_, err = ctx.Exec("bash", []interface{}{"-c", "exit 1"}, "")
require.Error(t, err, "Expected error to be returned when executing command with non-zero exit code")
}