-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.go
44 lines (35 loc) · 1.03 KB
/
handler_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
package pubsub
import (
"context"
"errors"
"testing"
)
func TestDispatcher_MissingHandler(t *testing.T) {
d := Dispatcher(nil)
err := d.HandleMessage(context.Background(), &Message{})
if !errors.Is(err, ErrMissingHandler) {
t.Fatalf("expected missing handler error; got %+v", err)
}
}
func TestRecoverer(t *testing.T) {
wrappedHandler := WrapHandler(HandlerFunc(func(ctx context.Context, message *Message) error {
panic("problem")
}), Recoverer)
err := wrappedHandler.HandleMessage(context.Background(), nil)
if err == nil {
t.Fatalf("expected error from recovered panic; got %v", err)
}
}
func TestAcknowledge(t *testing.T) {
h := Acknowledge(HandlerFunc(func(ctx context.Context, message *Message) error {
return nil
}))
var msg Message
err := h.HandleMessage(context.Background(), &msg)
if err != nil {
t.Fatalf("unexpected error handling the message; got %v", err)
}
if err := msg.Ack(context.Background()); err != ErrReceivedMessageNotAvailable {
t.Fatalf("expected error acking the message; got %v", err)
}
}