56 lines
2.2 KiB
Go
56 lines
2.2 KiB
Go
package webui
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
|
"github.com/samcharles93/archie-core/internal/events"
|
|
"github.com/samcharles93/archie-core/internal/taskstate"
|
|
)
|
|
|
|
func TestEarlyAttemptHistory(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
events []events.Event
|
|
steps []task.StepExecution
|
|
status string
|
|
current int
|
|
want string
|
|
}{
|
|
{name: "current parked attempt without stage events", status: task.StatusParked, current: 3, want: "parked"},
|
|
{name: "retry preserves the previous park reason", events: []events.Event{{Attempt: 1, Kind: events.KindTaskRetried, Data: map[string]any{"previous_reason": "clone authentication failed"}}}, status: task.StatusRunning, current: 2, want: "parked"},
|
|
{name: "historical early failure", events: []events.Event{{Attempt: 1, Kind: events.KindParked, Detail: "clone failed"}}, status: task.StatusRunning, current: 2, want: "parked"},
|
|
{name: "step execution without events", steps: []task.StepExecution{{Attempt: 1, Kind: task.StepKindStage, Name: "prepare", Status: taskstate.StepFailed}}, status: task.StatusParked, current: 2, want: "failed"},
|
|
{name: "historical state has no recorded outcome", events: []events.Event{{Attempt: 1, Kind: events.KindTaskRetried}}, status: task.StatusRunning, current: 2, want: "unknown"},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
attempts := attemptsFromEvents(tc.events, tc.steps, tc.status, tc.current)
|
|
if len(attempts) == 0 {
|
|
t.Fatal("current attempt missing")
|
|
}
|
|
if attempts[0].Status != tc.want {
|
|
t.Fatalf("status = %s, want %s", attempts[0].Status, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestStageErrorByStatus(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
status taskstate.StepStatus
|
|
want string
|
|
}{
|
|
{taskstate.StepFailed, "boom"},
|
|
{taskstate.StepInterrupted, "boom"},
|
|
{taskstate.StepSkipped, ""},
|
|
{taskstate.StepSucceeded, ""},
|
|
} {
|
|
t.Run(string(tc.status), func(t *testing.T) {
|
|
steps := []task.StepExecution{{Kind: task.StepKindStage, Name: "build", Status: tc.status, Detail: "boom"}}
|
|
if got := stageViewsFromSteps(steps, false)[0].Error; got != tc.want {
|
|
t.Fatalf("error = %q, want %q", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|