28 lines
679 B
Go
28 lines
679 B
Go
package realtime
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestHubPublishesToTopicAndWildcardSubscribers(t *testing.T) {
|
|
hub := New()
|
|
topic, cancelTopic := hub.Subscribe("series:s1")
|
|
defer cancelTopic()
|
|
all, cancelAll := hub.Subscribe("*")
|
|
defer cancelAll()
|
|
|
|
hub.Publish("series:s1", map[string]int{"version": 2})
|
|
|
|
for name, channel := range map[string]<-chan Event{"topic": topic, "wildcard": all} {
|
|
select {
|
|
case event := <-channel:
|
|
if event.Topic != "series:s1" || string(event.Data) != `{"version":2}` {
|
|
t.Fatalf("%s subscriber received %#v", name, event)
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatalf("%s subscriber did not receive update", name)
|
|
}
|
|
}
|
|
}
|