summaryrefslogtreecommitdiff
path: root/events/events_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'events/events_test.go')
-rw-r--r--events/events_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/events/events_test.go b/events/events_test.go
index 6c501392..41944b48 100644
--- a/events/events_test.go
+++ b/events/events_test.go
@@ -20,3 +20,66 @@ func TestEvenHandler(t *testing.T) {
require.Equal(t, "http", evt.Plugin())
require.Equal(t, "EventJobOK", evt.Type().String())
}
+
+func TestEvenHandler2(t *testing.T) {
+ eh, id := Bus()
+ eh2, id2 := Bus()
+
+ ch := make(chan Event, 100)
+ ch2 := make(chan Event, 100)
+ err := eh2.SubscribeP(id2, "http.EventJobOK", ch)
+ require.NoError(t, err)
+
+ err = eh.SubscribeP(id, "http.EventJobOK", ch2)
+ require.NoError(t, err)
+
+ eh.Send(NewRREvent(EventJobOK, "foo", "http"))
+
+ evt := <-ch2
+ require.Equal(t, "foo", evt.Message())
+ require.Equal(t, "http", evt.Plugin())
+ require.Equal(t, "EventJobOK", evt.Type().String())
+
+ l := eh.Len()
+ require.Equal(t, uint(2), l)
+
+ eh.Unsubscribe(id)
+
+ l = eh.Len()
+ require.Equal(t, uint(1), l)
+
+ eh2.Unsubscribe(id2)
+
+ l = eh.Len()
+ require.Equal(t, uint(0), l)
+}
+
+func TestEvenHandler3(t *testing.T) {
+ eh, id := Bus()
+
+ ch := make(chan Event, 100)
+ err := eh.SubscribeP(id, "EventJobOK", ch)
+ require.Error(t, err)
+}
+
+func TestEvenHandler4(t *testing.T) {
+ eh, id := Bus()
+
+ err := eh.SubscribeP(id, "EventJobOK", nil)
+ require.Error(t, err)
+}
+
+func TestEvenHandler5(t *testing.T) {
+ eh, id := Bus()
+
+ ch := make(chan Event, 100)
+ err := eh.SubscribeP(id, "http.EventJobOK", ch)
+ require.NoError(t, err)
+
+ eh.Send(NewRREvent(EventJobOK, "foo", "http"))
+
+ evt := <-ch
+ require.Equal(t, "foo", evt.Message())
+ require.Equal(t, "http", evt.Plugin())
+ require.Equal(t, "EventJobOK", evt.Type().String())
+}