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.go56
1 files changed, 44 insertions, 12 deletions
diff --git a/events/events_test.go b/events/events_test.go
index e15c55d6..f7cb4205 100644
--- a/events/events_test.go
+++ b/events/events_test.go
@@ -12,15 +12,15 @@ func TestEvenHandler(t *testing.T) {
defer eh.Unsubscribe(id)
ch := make(chan Event, 100)
- err := eh.SubscribeP(id, "http.EventJobOK", ch)
+ err := eh.SubscribeP(id, "http.EventWorkerError", ch)
require.NoError(t, err)
- eh.Send(NewEvent(EventJobOK, "http", "foo"))
+ eh.Send(NewEvent(EventWorkerError, "http", "foo"))
evt := <-ch
require.Equal(t, "foo", evt.Message())
require.Equal(t, "http", evt.Plugin())
- require.Equal(t, "EventJobOK", evt.Type().String())
+ require.Equal(t, "EventWorkerError", evt.Type().String())
}
func TestEvenHandler2(t *testing.T) {
@@ -31,18 +31,18 @@ func TestEvenHandler2(t *testing.T) {
ch := make(chan Event, 100)
ch2 := make(chan Event, 100)
- err := eh2.SubscribeP(id2, "http.EventJobOK", ch)
+ err := eh2.SubscribeP(id2, "http.EventWorkerError", ch)
require.NoError(t, err)
- err = eh.SubscribeP(id, "http.EventJobOK", ch2)
+ err = eh.SubscribeP(id, "http.EventWorkerError", ch2)
require.NoError(t, err)
- eh.Send(NewEvent(EventJobOK, "http", "foo"))
+ eh.Send(NewEvent(EventWorkerError, "http", "foo"))
evt := <-ch2
require.Equal(t, "foo", evt.Message())
require.Equal(t, "http", evt.Plugin())
- require.Equal(t, "EventJobOK", evt.Type().String())
+ require.Equal(t, "EventWorkerError", evt.Type().String())
l := eh.Len()
require.Equal(t, uint(2), l)
@@ -65,7 +65,7 @@ func TestEvenHandler3(t *testing.T) {
defer eh.Unsubscribe(id)
ch := make(chan Event, 100)
- err := eh.SubscribeP(id, "EventJobOK", ch)
+ err := eh.SubscribeP(id, "EventWorkerError", ch)
require.Error(t, err)
}
@@ -73,7 +73,7 @@ func TestEvenHandler4(t *testing.T) {
eh, id := Bus()
defer eh.Unsubscribe(id)
- err := eh.SubscribeP(id, "EventJobOK", nil)
+ err := eh.SubscribeP(id, "EventWorkerError", nil)
require.Error(t, err)
}
@@ -82,13 +82,45 @@ func TestEvenHandler5(t *testing.T) {
defer eh.Unsubscribe(id)
ch := make(chan Event, 100)
- err := eh.SubscribeP(id, "http.EventJobOK", ch)
+ err := eh.SubscribeP(id, "http.EventWorkerError", ch)
require.NoError(t, err)
- eh.Send(NewEvent(EventJobOK, "http", "foo"))
+ eh.Send(NewEvent(EventWorkerError, "http", "foo"))
evt := <-ch
require.Equal(t, "foo", evt.Message())
require.Equal(t, "http", evt.Plugin())
- require.Equal(t, "EventJobOK", evt.Type().String())
+ require.Equal(t, "EventWorkerError", evt.Type().String())
+}
+
+type MySuperEvent uint32
+
+const (
+ // EventHTTPError represents success unary call response
+ EventHTTPError MySuperEvent = iota
+)
+
+func (mse MySuperEvent) String() string {
+ switch mse {
+ case EventHTTPError:
+ return "EventHTTPError"
+ default:
+ return "UnknownEventType"
+ }
+}
+
+func TestEvenHandler6(t *testing.T) {
+ eh, id := Bus()
+ defer eh.Unsubscribe(id)
+
+ ch := make(chan Event, 100)
+ err := eh.SubscribeP(id, "http.EventHTTPError", ch)
+ require.NoError(t, err)
+
+ eh.Send(NewEvent(EventHTTPError, "http", "foo"))
+
+ evt := <-ch
+ require.Equal(t, "foo", evt.Message())
+ require.Equal(t, "http", evt.Plugin())
+ require.Equal(t, "EventHTTPError", evt.Type().String())
}