Skip to content
quarry Artifact [53c6235ee1]
Login

Artifact [53c6235ee1]

Artifact 53c6235ee1b3fc04e1d177777c08337aeda0e93e233c995e68c592ca69104a5e:


package oltp

import (
	"path/filepath"
	"testing"
)

// A terminal run records when it finished; the migration leaves old
// rows readable with an empty stamp rather than failing the scan.
func TestCompleteCIRunStampsOnce(t *testing.T) {
	db, err := Open(filepath.Join(t.TempDir(), "o.db"))
	if err != nil {
		t.Fatal(err)
	}
	defer db.Close()
	if err := db.AddCIRun(CIRun{RunID: "r1", Repo: "alpha", Checkin: "c1",
		Workflow: "w", Pipeline: "ci/p.json", Status: "running"}); err != nil {
		t.Fatal(err)
	}
	rows, _ := db.CIRuns("alpha", 10)
	if len(rows) != 1 || rows[0].Completed != "" {
		t.Fatalf("a running run has a completion stamp: %+v", rows)
	}
	if err := db.CompleteCIRun("r1", "failed", "2026-08-29T12:00:00Z"); err != nil {
		t.Fatal(err)
	}
	rows, _ = db.CIRuns("alpha", 10)
	if rows[0].Status != "failed" || rows[0].Completed != "2026-08-29T12:00:00Z" {
		t.Fatalf("terminal transition not recorded: %+v", rows[0])
	}
	if err := db.CompleteCIRun("r2", "completed", ""); err != nil {
		t.Fatal(err) // unknown run: harmless
	}
}