package web
import (
"strings"
"testing"
)
// A cancelled run is stopped, not broken. The landing panel counted it
// as a failure, which both misnamed it and — because the failing
// branch wins the summary switch — hid the fact that a REQUIRED check
// had no result and could be asked for again.
func TestACancelledRunIsNotAFailure(t *testing.T) {
l := landingDetail{
Checks: []ciRunRow{{Status: "cancelled", Pipeline: "ci/quarry.json"}},
Unmet: []string{"quarry"},
}
got := l.ChecksSummary()
if got.State == "fail" {
t.Errorf("FAIL: a cancelled run still reads as a failure: %+v", got)
}
// The reader is told what to do about it.
if !strings.Contains(got.Headline+" "+got.Subline, "cancelled") {
t.Errorf("FAIL: the summary does not say the run was cancelled: %+v", got)
}
if !strings.Contains(got.Headline+" "+got.Subline, "re-run") {
t.Errorf("FAIL: the summary offers no way forward: %+v", got)
}
// The required check is still named, because that is what has to
// go green before this can be accepted.
if !strings.Contains(got.Subline, "quarry") {
t.Errorf("FAIL: the unmet required check is not named: %+v", got)
}
}
// A real failure still wins: cancelling one run does not soften a
// verdict another run actually reported.
func TestARealFailureStillOutranksACancellation(t *testing.T) {
l := landingDetail{Checks: []ciRunRow{
{Status: "cancelled", Pipeline: "ci/slow.json"},
{Status: "failed", Pipeline: "ci/quarry.json"},
}}
if got := l.ChecksSummary(); got.State != "fail" {
t.Errorf("FAIL: a failing check stopped being a failure: %+v", got)
}
}