diff --git a/exec.go b/exec.go index b1a7de7..5664645 100644 --- a/exec.go +++ b/exec.go @@ -59,6 +59,7 @@ type ExecTask struct { type ExecResult struct { Stdout string Stderr string + Error error ExitCode int Cancelled bool } @@ -187,6 +188,7 @@ func (et ExecTask) Execute(ctx context.Context) (ExecResult, error) { return ExecResult{ Stdout: stdoutBuff.String(), Stderr: stderrBuff.String(), + Error: execErr, ExitCode: exitCode, Cancelled: ctx.Err() == context.Canceled, }, ctx.Err() diff --git a/exec_test.go b/exec_test.go index 9cd3290..a63c9db 100644 --- a/exec_test.go +++ b/exec_test.go @@ -27,6 +27,9 @@ func TestExec_ReturnErrorForUnknownCommand(t *testing.T) { if res.Cancelled != false { t.Fatalf("want not cancelled, but got true") } + if res.Error != nil { + t.Fatalf("want nil error, but got %s", err.Error()) + } if res.ExitCode != 0 { t.Fatalf("want exit code 0, but got %d", res.ExitCode) } @@ -56,6 +59,10 @@ func TestExec_ContextAlreadyCancelled(t *testing.T) { t.Fatalf("want cancelled, but got false") } + if res.Error == nil { + t.Fatalf("want non-nil error, but got nil") + } + if res.ExitCode != -1 { t.Fatalf("want exit code -1, but got %d", res.ExitCode) } @@ -81,6 +88,10 @@ func TestExec_ContextCancelledDuringExecution(t *testing.T) { t.Fatalf("want cancelled, but got false") } + if res.Error == nil { + t.Fatalf("want non-nil error, but got nil") + } + if res.ExitCode != -1 { t.Fatalf("want exit code -1, but got %d", res.ExitCode) } @@ -106,6 +117,10 @@ func TestExecShell_ContextCancelledDuringExecution(t *testing.T) { t.Fatalf("want cancelled, but got false") } + if res.Error == nil { + t.Fatalf("want non-nil error, but got nil") + } + if res.ExitCode != -1 { t.Fatalf("want exit code -1, but got %d", res.ExitCode) }