package api
import "testing"
// Trunk's state is its tip's: running while any of the tip's runs is,
// a cancelled run is not running, and a tip with no run says nothing.
func TestTrunkCIReadsTheTipsRuns(t *testing.T) {
tip := "aaaa"
repo := &Repo{}
cases := []struct {
name string
runs []CIRun
want string
}{
{"running", []CIRun{{Checkin: tip, Status: "running"}}, "running"},
{"another check-in's run", []CIRun{{Checkin: "bbbb", Status: "running"}}, ""},
{"cancelled", []CIRun{{Checkin: tip, Status: "cancelled", Completed: "x"}}, ""},
{"finished, no verdict indexed", []CIRun{{Checkin: tip, Status: "completed", Completed: "x"}}, ""},
}
for _, c := range cases {
if got, _ := trunkCI(repo, c.runs, tip); got != c.want {
t.Errorf("FAIL: %s: trunk reads %q, want %q", c.name, got, c.want)
}
}
if got, at := trunkCI(repo, []CIRun{{Checkin: tip, Status: "running"}}, ""); got != "" || at != "" {
t.Error("FAIL: a repository with no tip reported a trunk state")
}
}