package web
import (
"strings"
"testing"
)
// The fleet page says in one line whether the mirrors are all right,
// and names the failing ones with their streak — before any form. 29
// silent failures were how an outage went unnoticed (a06c9ad3).
func TestTheFleetPageSummarisesMirrorsAndNamesTheFailing(t *testing.T) {
var sb strings.Builder
rows := []mirrorRow{
{Repo: "fossil", Enabled: true, State: "current"},
{Repo: "wapp", Enabled: true, State: "behind", Failures: 29, LastErr: "dial tcp: no such host"},
{Repo: "old", Enabled: false},
}
err := noHooks.template(fleetAdminPage).ExecuteTemplate(&sb, "fleet-mirrors", pageData{
Mirrors: rows,
MirrorCounts: map[string]int{"all": 2, "current": 1, "failing": 1},
})
if err != nil {
t.Fatal(err)
}
body := sb.String()
if !strings.Contains(body, `data-hook="mirror-summary" data-all="2" data-failing="1"`) {
t.Fatal("FAIL: no summary line carrying the counts as data")
}
if !strings.Contains(body, "wapp, 29 attempts") || strings.Contains(body, "fossil, ") {
t.Fatal("FAIL: the failing mirror is not named with its streak, or a healthy one is")
}
t.Log("ok: 2 mirrors · 1 current · 1 failing, wapp named with 29 attempts")
}