-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublisher_test.go
More file actions
51 lines (44 loc) · 1.54 KB
/
publisher_test.go
File metadata and controls
51 lines (44 loc) · 1.54 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
40
41
42
43
44
45
46
47
48
49
50
51
package platform
import (
"errors"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestMultiPublisher(t *testing.T) {
Convey("A multi publisher without any publishers should return an error on publish", t, func() {
multiPublisher := NewMultiPublisher(nil)
So(multiPublisher.Publish("testing", []byte{}), ShouldResemble, errors.New("No publishers have been declared in the multi publisher"))
})
Convey("A multi publisher should round robin publishes", t, func() {
mockPublisher1 := newMockPublisher()
mockPublisher2 := newMockPublisher()
multiPublisher := NewMultiPublisher([]Publisher{mockPublisher1, mockPublisher2})
So(multiPublisher, ShouldNotBeNil)
So(multiPublisher.offset, ShouldEqual, 0)
So(mockPublisher1.mockPublishes, ShouldResemble, []mockPublish{})
So(mockPublisher2.mockPublishes, ShouldResemble, []mockPublish{})
So(multiPublisher.Publish("testing-1", []byte{}), ShouldBeNil)
So(multiPublisher.offset, ShouldEqual, 1)
So(mockPublisher1.mockPublishes, ShouldResemble, []mockPublish{
mockPublish{
topic: "testing-1",
body: []byte{},
},
})
So(mockPublisher2.mockPublishes, ShouldResemble, []mockPublish{})
So(multiPublisher.Publish("testing-2", []byte{}), ShouldBeNil)
So(multiPublisher.offset, ShouldEqual, 0)
So(mockPublisher1.mockPublishes, ShouldResemble, []mockPublish{
mockPublish{
topic: "testing-1",
body: []byte{},
},
})
So(mockPublisher2.mockPublishes, ShouldResemble, []mockPublish{
mockPublish{
topic: "testing-2",
body: []byte{},
},
})
})
}