feat: add cli contract and local browser events

This commit is contained in:
QiuSW
2026-07-22 15:19:11 +08:00
parent 82f3c1be0e
commit 26cfa8b921
8 changed files with 210 additions and 6 deletions
+33
View File
@@ -0,0 +1,33 @@
package application
import (
"testing"
"time"
"chub/internal/domain"
)
func TestEventBusPublishesAndCancels(t *testing.T) {
bus := NewEventBus()
ch, cancel := bus.Subscribe(1)
event := domain.BrowserEvent{Kind: domain.EventBrowserStarted, InstanceID: "demo"}
bus.Publish(event)
select {
case got := <-ch:
if got.InstanceID != event.InstanceID || got.Kind != event.Kind {
t.Fatalf("unexpected event: %#v", got)
}
case <-time.After(time.Second):
t.Fatal("event was not published")
}
cancel()
bus.Publish(event)
select {
case _, ok := <-ch:
if ok {
t.Fatal("cancelled subscriber received an event")
}
case <-time.After(time.Second):
t.Fatal("subscriber was not closed")
}
}