package web
import (
"regexp"
"strings"
"testing"
)
func eventWindowLine(t *testing.T, d pageData) (string, bool) {
t.Helper()
d.Ops.BudgetMs = 500
var buf strings.Builder
if err := noHooks.template(opsPage).ExecuteTemplate(&buf, "content", d); err != nil {
t.Fatal(err)
}
m := regexp.MustCompile(`<p [^>]*data-hook="event-stream-window"[^>]*>`).FindString(buf.String())
return m, m != ""
}
// The window sits with the lanes: its first sequence is the oldest
// position a store can resume from without a rebuild.
func TestTheOpsPageShowsTheEventStreamWindow(t *testing.T) {
var d pageData
d.Ops.EventStream = &opsEventStreamView{FirstSeq: 7464, LastSeq: 7577, Msgs: 114,
Bytes: 5_000_000, OldestAgeMs: 57 * 60_000, MaxAgeSeconds: 7 * 86400}
tag, ok := eventWindowLine(t, d)
if !ok {
t.Fatal("FAIL: the ops page draws no event stream window")
}
for _, want := range []string{`data-first="7464"`, `data-last="7577"`, `data-oldest-age-ms="3420000"`, `data-max-age-seconds="604800"`} {
if !strings.Contains(tag, want) {
t.Errorf("FAIL: the window line lacks %s: %s", want, tag)
}
}
if _, ok := eventWindowLine(t, pageData{}); ok {
t.Error("FAIL: a window drawn with no event stream reported")
}
}