package app import ( "encoding/json" "net/http" "os" "sort" "testing" ) // TestDumpShapes prints the real shape of every admin endpoint. It is a // development aid, not an assertion: run it with // // go test ./internal/app/ -run TestDumpShapes -v // // when changing a response struct, and diff the output against // web/src/lib/types.ts. Delete it once the contract test covers everything. func TestDumpShapes(t *testing.T) { if os.Getenv("DUMP_SHAPES") == "" { t.Skip("set DUMP_SHAPES=1") } h := newHarness(t, nil) h.query("hot.test.", 1) for _, p := range []string{ "/api/status", "/api/blocklists", "/api/domains?per_page=3", "/api/clients", "/api/upstreams", "/api/cache", "/api/settings", "/api/whoami", } { code, body := h.get(p) var keys []string var m map[string]json.RawMessage if json.Unmarshal(body, &m) == nil { for k := range m { keys = append(keys, k) } sort.Strings(keys) } t.Logf("%-28s %d %v", p, code, keys) var pretty any if json.Unmarshal(body, &pretty) == nil { b, _ := json.MarshalIndent(pretty, " ", " ") if len(b) > 1200 { b = b[:1200] } t.Logf("%s", b) } } for _, m := range []struct{ method, path, body string }{ {http.MethodPost, "/api/blocklists/refresh", `{"names":[]}`}, {http.MethodPost, "/api/cache/flush", ""}, } { code, body := h.do(m.method, m.path, m.body) t.Logf("%s %s -> %d %s", m.method, m.path, code, body) } }