2024-08-02 20:57:56 +00:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTaskHasErrorReturnsFalseIfNoUnderlyingJobHaveErrors(t *testing.T) {
|
2024-08-17 04:18:53 +00:00
|
|
|
task := NewTaskTracker(nil)
|
|
|
|
NewTaskTracker(task)
|
2024-08-02 20:57:56 +00:00
|
|
|
|
|
|
|
if task.HasError() {
|
|
|
|
t.Errorf("Expected false, got true.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTaskHasErrorReturnsTrueIfAnyJobHasErrors(t *testing.T) {
|
2024-08-17 04:18:53 +00:00
|
|
|
task := NewTaskTracker(nil)
|
2024-08-02 20:57:56 +00:00
|
|
|
|
|
|
|
// Two jobs, one of which has an error.
|
2024-08-17 04:18:53 +00:00
|
|
|
NewTaskTracker(task)
|
|
|
|
subTask := NewTaskTracker(task)
|
2024-08-02 20:57:56 +00:00
|
|
|
|
2024-08-17 04:18:53 +00:00
|
|
|
subTask.SetError(errors.New("test"))
|
2024-08-02 20:57:56 +00:00
|
|
|
|
|
|
|
if !task.HasError() {
|
|
|
|
t.Errorf("Expected true, got false.")
|
|
|
|
}
|
|
|
|
}
|
2024-08-20 03:35:33 +00:00
|
|
|
|
|
|
|
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.")
|
|
|
|
}
|
|
|
|
}
|