37 lines
1.6 KiB
Go
37 lines
1.6 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)
|
|
}
|
|
})
|
|
}
|
|
}
|