-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpipe_test.go
45 lines (41 loc) · 1.12 KB
/
pipe_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
package ziggurat
import (
"context"
"testing"
"time"
)
func TestPipeHandlers(t *testing.T) {
mw1 := func(next Handler) Handler {
return HandlerFunc(func(ctx context.Context, messageEvent *Event) {
me := Event{
Value: []byte("foo"),
Key: nil,
ProducerTimestamp: time.Time{},
ReceivedTimestamp: time.Time{},
EventType: "",
}
next.Handle(ctx, &me)
})
}
mw2 := func(next Handler) Handler {
return HandlerFunc(func(ctx context.Context, messageEvent *Event) {
byteValue := append(messageEvent.Value, []byte("-bar")...)
me := Event{
RoutingPath: "",
Value: byteValue,
Key: nil,
ProducerTimestamp: time.Time{},
ReceivedTimestamp: time.Time{},
EventType: "",
}
next.Handle(ctx, &me)
})
}
actualHandler := HandlerFunc(func(ctx context.Context, event *Event) {
if string(event.Value) != "foo-bar" {
t.Errorf("expected message to be %s,but got %s", "foo-bar", string(event.Value))
}
})
finalHandler := pipe(actualHandler, mw1, mw2)
finalHandler.Handle(context.Background(), &Event{})
}