Skip to content

Commit

Permalink
tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevhen Terentiev committed May 15, 2020
1 parent 968befa commit 3e89144
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion internal/context/context.go
Expand Up @@ -108,7 +108,7 @@ func (c *ExecutionContext) runServiceCommand(command string) (err error) {
Env: c.Env,
})
if err != nil {
if executor.IsExitStatus(err) {
if _, ok := executor.IsExitStatus(err); ok {
return fmt.Errorf("%v\n%s\n%s\n", err, out, err.Error())
} else {
return err
Expand Down
5 changes: 2 additions & 3 deletions internal/executor/executor.go
Expand Up @@ -105,7 +105,6 @@ func (e *DefaultExecutor) Execute(ctx context.Context, job *Job) ([]byte, error)
return buf.Bytes(), nil
}

func IsExitStatus(err error) bool {
_, ok := interp.IsExitStatus(err)
return ok
func IsExitStatus(err error) (uint8, bool) {
return interp.IsExitStatus(err)
}
7 changes: 7 additions & 0 deletions internal/pipeline/scheduler_test.go
@@ -1,6 +1,7 @@
package pipeline

import (
"errors"
"testing"

"github.com/taskctl/taskctl/internal/task"
Expand All @@ -10,6 +11,12 @@ type TestTaskRunner struct {
}

func (t2 TestTaskRunner) Run(t *task.Task) error {
if t.Commands[0] == "/usr/bin/false" {
t.ExitCode = 1
t.Errored = true
return errors.New("task failed")
}

return nil
}

Expand Down
19 changes: 12 additions & 7 deletions internal/runner/runner.go
Expand Up @@ -52,6 +52,10 @@ func NewTaskRunner(contexts map[string]*taskctx.ExecutionContext, vars variables
return nil, err
}

if vars == nil {
vars = variables.NewVariables(nil)
}

r := &TaskRunner{
Executor: exec,
OutputFormat: output.OutputFormatRaw,
Expand Down Expand Up @@ -175,17 +179,16 @@ func (r *TaskRunner) Run(t *task.Task) error {
prevOutput, err = r.Executor.Execute(r.ctx, nextJob)
if err != nil {
logrus.Debug(err.Error())
if utils.IsExitError(err) && t.AllowFailure {
continue
if status, ok := executor.IsExitStatus(err); ok {
t.ExitCode = int16(status)
if t.AllowFailure {
continue
}
}
t.Errored = true
t.Error = err
break
}

if t.Errored {
break
}
}
t.End = time.Now()

Expand All @@ -196,6 +199,8 @@ func (r *TaskRunner) Run(t *task.Task) error {

if t.Errored {
return t.Error
} else {
t.ExitCode = 0
}

r.storeTaskOutput(t)
Expand Down Expand Up @@ -285,7 +290,7 @@ func (r *TaskRunner) checkTaskCondition(t *task.Task) (bool, error) {

_, err = r.Executor.Execute(r.ctx, j)
if err != nil {
if executor.IsExitStatus(err) {
if _, ok := executor.IsExitStatus(err); ok {
return false, nil
}

Expand Down
5 changes: 3 additions & 2 deletions internal/runner/runner_test.go
@@ -1,6 +1,7 @@
package runner

import (
"github.com/taskctl/taskctl/internal/variables"
"testing"

taskpkg "github.com/taskctl/taskctl/internal/task"
Expand All @@ -9,11 +10,11 @@ import (
func TestTaskRunner_Run(t *testing.T) {
task := taskpkg.NewTask()

task.Commands = []string{"/bin/true"}
task.Commands = []string{"/usr/bin/true"}
task.Name = "some test task"
task.Dir = "{{.Root}}"

runner, err := NewTaskRunner(nil, nil)
runner, err := NewTaskRunner(nil, variables.NewVariables(map[string]string{"Root": "/tmp"}))
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/task/task.go
Expand Up @@ -37,7 +37,7 @@ type Task struct {

ExportAs string

ExitCode int
ExitCode int16
Errored bool
Error error
Log struct {
Expand Down

0 comments on commit 3e89144

Please sign in to comment.