Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
28 lines
1.0 KiB
Go
28 lines
1.0 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestTheGuardrailsPageShowsNamesAndCounts(t *testing.T) {
|
|
rec := httptest.NewRecorder()
|
|
render(rec, "admin_guard", guardPageData{
|
|
Nav: Nav{Admin: true, Guard: true, Current: "guard"}, Window: "7d", Windows: []string{"24h", "7d"},
|
|
Policies: []string{"base", "finance"}, Default: []string{"base"},
|
|
Attachments: []guardAttachmentRow{{Scope: "project", Who: "Acme/fin/payroll", Policy: "finance"}},
|
|
Counts: []guardCountRow{{Where: "Acme/fin/payroll", Action: "blocked", Policy: "base,finance", Category: "iban", Count: 3}},
|
|
Events: []guardEventRow{{At: "2026-10-04 10:00:00", RequestID: "req_1", Action: "blocked", Category: "iban", Status: 400}},
|
|
})
|
|
body := rec.Body.String()
|
|
for _, want := range []string{"Acme/fin/payroll", "base,finance", "req_1", `href="/admin/guard" aria-current="page"`, `href="?window=24h"`} {
|
|
if !strings.Contains(body, want) {
|
|
t.Errorf("no %q", want)
|
|
}
|
|
}
|
|
if rec.Code != 200 {
|
|
t.Errorf("status %d: %s", rec.Code, body)
|
|
}
|
|
}
|