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:
@@ -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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user