Skip to content
quarry Artifact [a0a33a9578]
Login

Artifact [a0a33a9578]

Artifact a0a33a9578d835df697183d85970d736bce0fb1daf913cf19c2d8a5a3aa867a3:


package web

import (
	"bytes"
	"strings"
	"testing"
)

// The recent renders can be narrowed to one surface. The control rides
// the page's own form, and the live refresh asks with the page's query
// so a tick does not reset it.
func TestOpsRecentRendersHaveASurfaceFilter(t *testing.T) {
	var b bytes.Buffer
	if err := noHooks.template(opsPage).Execute(&b, pageData{Ops: opsView{Surface: "api"}, FleetTab: "ops"}); err != nil {
		t.Fatal(err)
	}
	html := b.String()
	i := strings.Index(html, `data-hook="ops-surface-filter"`)
	if i < 0 {
		t.Fatal("no surface filter control on the ops page")
	}
	ctl := html[strings.LastIndex(html[:i], "<select"):]
	ctl = ctl[:strings.Index(ctl, "</select>")]
	for _, want := range []string{`name="surface"`, `form="ops-controls"`, `value=""`,
		`value="web"`, `value="api" selected`} {
		if !strings.Contains(ctl, want) {
			t.Errorf("surface control lacks %s:\n%s", want, ctl)
		}
	}
	if !strings.Contains(html, `id="ops-controls"`) {
		t.Error("the control names a form the page does not have")
	}
	if !strings.Contains(html, `@get('/fleet/ops.sse' + location.search)`) {
		t.Error("the live refresh does not carry the page's query")
	}
}

// Rows the history store had to drop are shown on the health panel, as
// a number with a hook; a store that dropped nothing shows no count.
func TestOpsHealthShowsDroppedRows(t *testing.T) {
	for _, dropped := range []uint64{0, 7} {
		var v opsView
		remarshal(map[string]any{"store": map[string]any{
			"configured": true, "path": "/x/ops.duckdb", "dropped": dropped}}, &v)
		var b bytes.Buffer
		if err := noHooks.template(opsPage).ExecuteTemplate(&b, "ops-body", pageData{Ops: v}); err != nil {
			t.Fatal(err)
		}
		html := b.String()
		has := strings.Contains(html, `data-hook="ops-dropped"`)
		if dropped == 0 && has {
			t.Error("a store that dropped nothing shows a dropped count")
		}
		if dropped > 0 && (!has || !strings.Contains(html, `data-dropped="7"`)) {
			t.Errorf("the dropped count is not on the health panel:\n%s", html)
		}
	}
}