-
Notifications
You must be signed in to change notification settings - Fork 32
/
pubsub_test.go
60 lines (47 loc) · 1.56 KB
/
pubsub_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package wireless
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestSubscribe(t *testing.T) {
Convey("given a connection", t, func() {
c := &Conn{}
Convey("when Subscribed to a Connected event", func() {
sub := c.Subscribe(EventConnected)
Convey("then it should have Connected in it's topics", func() {
So(sub.topics, ShouldEqual, EventConnected)
})
Convey("and a Connected event is pushed", func() {
c.publishEvent(Event{Name: EventConnected, Arguments: map[string]string{"a": "b"}})
Convey("then the subscription should get the event", func() {
So(sub.ch, ShouldHaveLength, 1)
ev := <-sub.Next()
So(ev.Name, ShouldEqual, EventConnected)
So(ev.Arguments, ShouldContainKey, "a")
So(ev.Arguments["a"], ShouldEqual, "b")
})
})
Convey("and then unsubscribed", func() {
sub.Unsubscribe()
Convey("then publishing should not panic", func() {
So(func() { c.publishEvent(Event{Name: EventConnected}) }, ShouldNotPanic)
So(func() { sub.publish(Event{Name: EventConnected}) }, ShouldNotPanic)
})
})
})
Convey("when Subscribed to nothing", func() {
sub := c.Subscribe()
Convey("then it should have Connected in it's topics", func() {
So(sub.topics, ShouldEqual, "")
})
Convey("and a Connectd event is pushed", func() {
c.publishEvent(Event{Name: EventConnected})
Convey("then the subscription should get the event", func() {
So(sub.ch, ShouldHaveLength, 1)
ev := <-sub.Next()
So(ev.Name, ShouldEqual, EventConnected)
})
})
})
})
}