-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesthandlers_test.go
94 lines (70 loc) · 1.78 KB
/
testhandlers_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package rabbitmq_test
import (
"context"
"errors"
"fmt"
"sync"
eh "github.com/Clarilab/eventhorizon"
)
const (
handler1Topic = "handler-1-topic"
handler2Topic = "handler-2-topic"
)
const (
Handler1Event = eh.EventType("handler-1-event")
Handler2Event = eh.EventType("handler-2-event")
)
func RegisterEvents() {
eh.RegisterEventData(Handler1Event, func() eh.EventData { return new(HandlerEventData) })
eh.RegisterEventData(Handler2Event, func() eh.EventData { return new(HandlerEventData) })
}
func UnregisterEvents() {
eh.UnregisterEventData(Handler1Event)
eh.UnregisterEventData(Handler2Event)
}
type handler1 struct {
wg *sync.WaitGroup
}
func (*handler1) HandlerType() eh.EventHandlerType {
return eh.EventHandlerType("test-handler-1")
}
func (h *handler1) HandleEvent(_ context.Context, _ eh.Event) error {
h.wg.Done()
return nil
}
func (*handler1) Events() eh.MatchEvents {
return eh.MatchEvents{
Handler1Event,
}
}
func (*handler1) Topic() string {
return handler1Topic
}
type HandlerEventData struct{}
type handler2 struct {
wg *sync.WaitGroup
}
func (*handler2) HandlerType() eh.EventHandlerType {
return eh.EventHandlerType("test-handler-2")
}
func (h *handler2) HandleEvent(_ context.Context, _ eh.Event) error {
h.wg.Done()
return nil
}
func (*handler2) Events() eh.MatchEvents {
return eh.MatchEvents{
Handler2Event,
}
}
func (*handler2) Topic() string {
return handler2Topic
}
type mockErrorEventHandler struct{}
func (*mockErrorEventHandler) HandlerType() eh.EventHandlerType {
return eh.EventHandlerType("mock-event-handler")
}
var errTestError = errors.New("error-from-mock-event-handler")
func (*mockErrorEventHandler) HandleEvent(_ context.Context, _ eh.Event) error {
err := fmt.Errorf("failed to handle event: %w", errTestError)
return err
}