Add comprehensive Claude Code monitoring and realtime streaming to the K8s dashboard. Includes API endpoints for health, stats, summary, inventory, and live event streaming. Frontend provides overview, usage, inventory, debug, and live feed views.
42 lines
964 B
Go
42 lines
964 B
Go
package claude
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestEventHub_PublishSubscribe(t *testing.T) {
|
|
hub := NewEventHub(10)
|
|
ch, cancel := hub.Subscribe()
|
|
defer cancel()
|
|
|
|
hub.Publish(Event{TS: time.Unix(1, 0), Type: EventTypeServerNotice, Data: map[string]any{"msg": "hi"}})
|
|
|
|
select {
|
|
case ev := <-ch:
|
|
if ev.Type != EventTypeServerNotice {
|
|
t.Fatalf("type=%s", ev.Type)
|
|
}
|
|
if ev.ID == 0 {
|
|
t.Fatalf("expected id to be assigned")
|
|
}
|
|
default:
|
|
t.Fatalf("expected event")
|
|
}
|
|
}
|
|
|
|
func TestEventHub_ReplaySince(t *testing.T) {
|
|
hub := NewEventHub(3)
|
|
hub.Publish(Event{TS: time.Unix(1, 0), Type: EventTypeServerNotice}) // id 1
|
|
hub.Publish(Event{TS: time.Unix(2, 0), Type: EventTypeServerNotice}) // id 2
|
|
hub.Publish(Event{TS: time.Unix(3, 0), Type: EventTypeServerNotice}) // id 3
|
|
|
|
got := hub.ReplaySince(1)
|
|
if len(got) != 2 {
|
|
t.Fatalf("len=%d", len(got))
|
|
}
|
|
if got[0].ID != 2 || got[1].ID != 3 {
|
|
t.Fatalf("ids=%d,%d", got[0].ID, got[1].ID)
|
|
}
|
|
}
|