feat: add cli contract and local browser events
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user