v1.1 plan: cancelled requests recorded as 499, empty usage is []; tests proven failing on master

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
2026-09-25 08:28:07 -07:00
co-authored by Claude Fable 5.1
parent bebee332a5
commit 9ba04b16e0
4 changed files with 233 additions and 0 deletions
@@ -0,0 +1,31 @@
package admin_test
import (
"encoding/json"
"strings"
"testing"
"git.wntrmute.dev/kyle/crossbar/internal/store"
)
// An empty usage table is an empty JSON array, not null: clients iterate it.
func TestUsageEmptyIsAnArray(t *testing.T) {
r := newRig(t)
for _, q := range []string{"/_crossbar/usage", "/_crossbar/usage?by=host", "/_crossbar/usage?by=model&since=1h"} {
rec := r.do(t, "GET", q, "")
if rec.Code != 200 {
t.Fatalf("%s: %d", q, rec.Code)
}
if strings.TrimSpace(rec.Body.String()) != "[]" {
t.Errorf("%s: body %q, want []", q, rec.Body.String())
}
var rows []store.UsageRow
if err := json.Unmarshal(rec.Body.Bytes(), &rows); err != nil || rows == nil || len(rows) != 0 {
t.Errorf("%s: decoded %v %v, want an empty non-nil slice", q, rows, err)
}
}
rec := r.do(t, "GET", "/_crossbar/usage?by=route", "", "Accept", "text/plain")
if rec.Code != 200 || !strings.Contains(rec.Body.String(), "key") {
t.Errorf("text form with no rows must still print the header: %d %q", rec.Code, rec.Body.String())
}
}