Review fixes: record cancelled requests as 499; empty usage is an array

Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
2026-09-25 09:00:31 -07:00
parent 74b8af4ce0
commit 9f5b50acf6
6 changed files with 201 additions and 17 deletions
+31
View File
@@ -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())
}
}