Skip to content
quarry Artifact [acace5a9a8]
Login

Artifact [acace5a9a8]

Artifact acace5a9a89e1b6b517e30c82d552d13154157aa04854eb9de27b24b656e595a:


package ci

import (
	"encoding/json"
	"testing"
)

func TestFirstStartPrefersEarliestAttempt(t *testing.T) {
	run := Run{Steps: map[string]Step{
		"a": {StartedAt: "2026-11-01T10:00:00Z", AttemptStartedAt: "2026-11-01T10:09:00Z"},
		"b": {StartedAt: "2026-11-01T10:00:01Z", AttemptStartedAt: "2026-11-01T10:05:00Z"},
		"c": {StartedAt: "2026-11-01T10:00:02Z"},
	}}
	if got := run.FirstStart(); got != "2026-11-01T10:05:00Z" {
		t.Errorf("FAIL: FirstStart = %q, want the earliest attempt_started_at", got)
	}
	if !t.Failed() {
		t.Log("ok")
	}
}

func TestFirstStartFallsBackToStartedAt(t *testing.T) {
	run := Run{Steps: map[string]Step{
		"a": {StartedAt: "2026-11-01T10:00:09Z"},
		"b": {StartedAt: "2026-11-01T10:00:03Z"},
		"c": {},
	}}
	if got := run.FirstStart(); got != "2026-11-01T10:00:03Z" {
		t.Errorf("FAIL: FirstStart = %q, want the earliest started_at", got)
	}
	if got := (Run{Steps: map[string]Step{"a": {}}}).FirstStart(); got != "" {
		t.Errorf("FAIL: FirstStart = %q for a run nothing began, want empty", got)
	}
	if !t.Failed() {
		t.Log("ok")
	}
}

func TestStepDecodesAttemptStartedAt(t *testing.T) {
	var st Step
	if err := json.Unmarshal([]byte(`{"attempt_started_at":"2026-11-01T10:05:00Z"}`), &st); err != nil {
		t.Fatal(err)
	}
	if st.AttemptStartedAt != "2026-11-01T10:05:00Z" {
		t.Errorf("FAIL: AttemptStartedAt = %q", st.AttemptStartedAt)
	}
	if !t.Failed() {
		t.Log("ok")
	}
}