courgette/internal/runner/task_test.go

56 lines
1.2 KiB
Go

package runner
import (
"errors"
"testing"
)
func TestTaskHasErrorReturnsFalseIfNoUnderlyingJobHaveErrors(t *testing.T) {
task := NewTaskTracker(nil)
NewTaskTracker(task)
if task.HasError() {
t.Errorf("Expected false, got true.")
}
}
func TestTaskHasErrorReturnsTrueIfAnyJobHasErrors(t *testing.T) {
task := NewTaskTracker(nil)
// Two jobs, one of which has an error.
NewTaskTracker(task)
subTask := NewTaskTracker(task)
subTask.SetError(errors.New("test"))
if !task.HasError() {
t.Errorf("Expected true, got false.")
}
}
func TestTaskFailedReturnsTrueIfAnyChildHasFailed(t *testing.T) {
task := NewTaskTracker(nil)
NewTaskTracker(task).SetStatus("failed")
if !task.Failed() {
t.Error("Expected failed = true, got false.")
}
}
func TestTaskFailedReturnsTrueIfTaskFailed(t *testing.T) {
task := NewTaskTracker(nil).SetStatus("failed")
NewTaskTracker(task)
if !task.Failed() {
t.Error("Expected failed = true, got false.")
}
}
func TeskTaskFailedReturnsFalseIfNeitherSelfOrChildrenFailed(t *testing.T) {
task := NewTaskTracker(nil).SetStatus("success")
NewTaskTracker(task)
if task.Failed() {
t.Error("Expected failed = false, got true.")
}
}