Skip to content
quarry Artifact [57961bef52]
Login

Artifact [57961bef52]

Artifact 57961bef52028fc301218942a5e57fcaaa5cb50f36920c54f0d3ef3e8bec5ea6:


package web

import (
	"strings"
	"testing"
)

// routeViewWith builds the drilldown's view with one render on it.
func routeViewWith(path, url, repo string) opsRouteView {
	var v opsRouteView
	v.Path = path
	v.Renders = append(v.Renders, struct {
		At        string `json:"at"`
		URL       string `json:"url"`
		Repo      string `json:"repo"`
		ElapsedMs int64  `json:"elapsedMs"`
		OpsMs     int64  `json:"opsMs"`
		ZitMs     int64  `json:"zitMs"`
		Status    int    `json:"status"`
		CallMs    int64  `json:"callMs"`
		Calls     []struct {
			Verb       string `json:"verb"`
			Repo       string `json:"repo"`
			DurationMs int64  `json:"durationMs"`
		} `json:"calls"`
	}{At: "2026-09-11T20:38:00Z", URL: url, Repo: repo, ElapsedMs: 3003, Status: 200})
	return v
}

// The drilldown exists because the route pattern hides the variable
// that matters, so it has to name the address. A dozen renders of
// GET /r/{repo}/ticket/{id} could say "tcl" and never which ticket —
// leaving a reader who found a three-second render with no way to go
// and look at it. obs.Render has carried URL all along for exactly this
// reason; the op dropped it and the panel never asked.
func TestTheRouteDrilldownNamesTheAddress(t *testing.T) {
	var buf strings.Builder
	err := noHooks.template(opsRoutePage).ExecuteTemplate(&buf, "content", pageData{
		Ops:      opsView{BudgetMs: 500},
		OpsRoute: routeViewWith("GET /r/{repo}/ticket/{id}", "/r/tcl/ticket/abc123", "tcl"),
	})
	if err != nil {
		t.Fatal(err)
	}
	got := buf.String()
	if !strings.Contains(got, "/r/tcl/ticket/abc123") {
		t.Error("FAIL: the drilldown does not name the address that was slow")
	}
	if !strings.Contains(got, `href="/r/tcl/ticket/abc123"`) {
		t.Error("FAIL: the address is not a link, so looking at the slow page is not one click")
	}
}

// A render with no recorded URL still says which repository it was,
// rather than showing a blank where the identifier belongs.
func TestARenderWithoutAnAddressStillNamesItsRepository(t *testing.T) {
	var buf strings.Builder
	if err := noHooks.template(opsRoutePage).ExecuteTemplate(&buf, "content", pageData{
		Ops:      opsView{BudgetMs: 500},
		OpsRoute: routeViewWith("GET /fleet", "", "tcl"),
	}); err != nil {
		t.Fatal(err)
	}
	if !strings.Contains(buf.String(), `href="/r/tcl"`) {
		t.Error("FAIL: a render with no URL lost its repository too")
	}
}