-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubscriber_test.go
More file actions
39 lines (31 loc) · 1.13 KB
/
subscriber_test.go
File metadata and controls
39 lines (31 loc) · 1.13 KB
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
package platform
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestMultiSubscriber(t *testing.T) {
Convey("Attempting to run a multi subscriber that has no subscribers should panic", t, func() {
multiSubscriber := NewMultiSubscriber(nil)
So(multiSubscriber.Run, ShouldPanic)
})
Convey("A multi subscriber should cascade calls to all subscribers", t, func() {
mockSubscriber1 := newMockSubscriber()
mockSubscriber2 := newMockSubscriber()
multiSubscriber := NewMultiSubscriber([]Subscriber{mockSubscriber1, mockSubscriber2})
So(multiSubscriber, ShouldNotBeNil)
So(mockSubscriber1.totalRunCalls, ShouldEqual, 0)
So(mockSubscriber2.totalRunCalls, ShouldEqual, 0)
multiSubscriber.Run()
So(mockSubscriber1.totalRunCalls, ShouldEqual, 1)
So(mockSubscriber2.totalRunCalls, ShouldEqual, 1)
multiSubscriber.Subscribe("testing", ConsumerHandlerFunc(func(body []byte) error {
return nil
}))
So(mockSubscriber1.getTopicTotalHandlers(), ShouldResemble, map[string]int{
"testing": 1,
})
So(mockSubscriber2.getTopicTotalHandlers(), ShouldResemble, map[string]int{
"testing": 1,
})
})
}