Skip to content
quarry Artifact [6ff5e98382]
Login

Artifact [6ff5e98382]

Artifact 6ff5e98382da68a8675ff6e743fdba7afc3943730bbc3d70dcd9391974ce8e88:


package oltp

import (
	"path/filepath"
	"testing"
)

// AN INHERITED VERDICT IS THE CHECK-IN'S OWN ROW, naming the run it
// came from and owing its verdict tag until completed; 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 != "" {
		t.Fatalf("FAIL: inherited row %+v; want p1's failed verdict on m1 itself", r)
	}
	if un, _ := db.UnfinishedCIRuns(); len(un) != 0 {
		t.Fatalf("FAIL: an inherited verdict is on the engine poller's work list: %+v", un)
	}
	if owed, _ := db.InheritedOwingVerdict(); len(owed) != 1 || owed[0].RunID != r.RunID {
		t.Fatalf("FAIL: verdicts owed %+v; want the inherited row until its tag is written", owed)
	}
	if err := db.CompleteCIRun(r.RunID, r.Status, ""); err != nil {
		t.Fatal(err)
	}
	if owed, _ := db.InheritedOwingVerdict(); len(owed) != 0 {
		t.Fatalf("FAIL: a completed inherited row still owes its verdict: %+v", owed)
	}
	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, with its source, owing its tag until completed; a note reads back")
}