-
Notifications
You must be signed in to change notification settings - Fork 10
/
router_test.go
49 lines (41 loc) · 1.13 KB
/
router_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
package mq_test
import (
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/stretchr/testify/assert"
mq "github.com/remind101/mq-go"
)
func TestRouter(t *testing.T) {
r := mq.NewRouter()
r.Handle("foo", mq.HandlerFunc(func(m *mq.Message) error { return nil }))
// No routing key
err := r.HandleMessage(&mq.Message{
SQSMessage: &sqs.Message{},
})
assert.Error(t, err)
assert.Equal(t, "no routing key for message", err.Error())
// Routing key does not match
err = r.HandleMessage(&mq.Message{
SQSMessage: &sqs.Message{
MessageAttributes: map[string]*sqs.MessageAttributeValue{
mq.MessageAttributeNameRoute: &sqs.MessageAttributeValue{
StringValue: aws.String("bar"),
},
},
},
})
assert.Error(t, err)
assert.Equal(t, "no handler matched for routing key: bar", err.Error())
// Matching routing key
err = r.HandleMessage(&mq.Message{
SQSMessage: &sqs.Message{
MessageAttributes: map[string]*sqs.MessageAttributeValue{
mq.MessageAttributeNameRoute: &sqs.MessageAttributeValue{
StringValue: aws.String("foo"),
},
},
},
})
assert.NoError(t, err)
}