|
|
|
@@ -9,6 +9,7 @@ import ( |
|
|
|
"testing" |
|
|
|
|
|
|
|
cfgpkg "github.com/jan/fm-rds-tx/internal/config" |
|
|
|
"github.com/jan/fm-rds-tx/internal/output" |
|
|
|
) |
|
|
|
|
|
|
|
func TestHealthz(t *testing.T) { |
|
|
|
@@ -55,6 +56,41 @@ func TestStatusReportsRuntimeIndicator(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestStatusReportsQueueStats(t *testing.T) { |
|
|
|
cfg := cfgpkg.Default() |
|
|
|
queueStats := output.QueueStats{ |
|
|
|
Capacity: cfg.Runtime.FrameQueueCapacity, |
|
|
|
Depth: 1, |
|
|
|
FillLevel: 0.25, |
|
|
|
Health: output.QueueHealthLow, |
|
|
|
} |
|
|
|
srv := NewServer(cfg) |
|
|
|
srv.SetTXController(&fakeTXController{stats: map[string]any{"queue": queueStats}}) |
|
|
|
rec := httptest.NewRecorder() |
|
|
|
srv.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/status", nil)) |
|
|
|
if rec.Code != 200 { |
|
|
|
t.Fatalf("status: %d", rec.Code) |
|
|
|
} |
|
|
|
var body map[string]any |
|
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil { |
|
|
|
t.Fatalf("unmarshal queue stats: %v", err) |
|
|
|
} |
|
|
|
queueRaw, ok := body["queue"] |
|
|
|
if !ok { |
|
|
|
t.Fatalf("missing queue in status") |
|
|
|
} |
|
|
|
queueMap, ok := queueRaw.(map[string]any) |
|
|
|
if !ok { |
|
|
|
t.Fatalf("queue stats type mismatch: %T", queueRaw) |
|
|
|
} |
|
|
|
if queueMap["capacity"] != float64(queueStats.Capacity) { |
|
|
|
t.Fatalf("queue capacity mismatch: want %v got %v", queueStats.Capacity, queueMap["capacity"]) |
|
|
|
} |
|
|
|
if queueMap["health"] != string(queueStats.Health) { |
|
|
|
t.Fatalf("queue health mismatch: want %s got %v", queueStats.Health, queueMap["health"]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestDryRunEndpoint(t *testing.T) { |
|
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
|
rec := httptest.NewRecorder() |
|
|
|
|