package oltp
import (
"path/filepath"
"testing"
)
// AN INHERITED VERDICT IS THE CHECK-IN'S OWN ROW, finished, naming the
// run it came from; recording it twice is one row; and a run's note
// reads back beside it.
func TestAnInheritedVerdictIsTheCheckinsOwn(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: "p1", Repo: "alpha", Checkin: "pair:b:t", Pair: "pair:b:t",
Workflow: "w", Pipeline: "ci/p.json", Status: "failed"}); err != nil {
t.Fatal(err)
}
for range 2 {
if err := db.InheritCIRun("alpha", "m1", "w", "ci/p.json", "failed", "p1"); err != nil {
t.Fatal(err)
}
}
rows, err := db.CIRunsFor("alpha", "m1")
if err != nil || len(rows) != 1 {
t.Fatalf("FAIL: m1's runs = %+v, %v; want the one inherited row", rows, err)
}
r := rows[0]
if r.InheritedFrom != "p1" || r.Status != "failed" || r.Pipeline != "ci/p.json" || r.Pair != "" || r.Completed == "" {
t.Fatalf("FAIL: inherited row %+v; want p1's failed verdict, finished, on m1 itself", r)
}
if un, _ := db.UnfinishedCIRuns(); len(un) != 0 {
t.Fatalf("FAIL: an inherited verdict is on the poller's work list: %+v", un)
}
if err := db.NoteCIRun("p1", "tested as the branch tip"); err != nil {
t.Fatal(err)
}
if rows, _ := db.CIRunsForPair("alpha", "pair:b:t"); len(rows) != 1 || rows[0].Note != "tested as the branch tip" {
t.Fatalf("FAIL: the noted run reads %+v", rows)
}
t.Log("ok: inherited once, finished, with its source; a note reads back")
}