-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutingkey_test.go
46 lines (33 loc) · 1.33 KB
/
routingkey_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
package messenger_amqp
import (
"github.com/riid/messenger/envelope"
"github.com/stretchr/testify/assert"
"testing"
)
func TestWithRoutingKey_will_add_routing_key_header_to_envelope(t *testing.T) {
e := envelope.FromMessage("test message")
eWithRoutingKey := WithRoutingKey(e, "test key")
routingKey, found := eWithRoutingKey.LastHeader(routingKeyHeaderName)
assert.True(t, found)
assert.Equal(t, "test key", routingKey)
assert.True(t, eWithRoutingKey.Is(e))
}
func TestRoutingKey_given_envelope_with_routing_key_will_return_it(t *testing.T) {
e := WithRoutingKey(envelope.FromMessage("test message"), "test key")
routingKey := RoutingKey(e)
assert.Equal(t, "test key", routingKey)
}
func TestRoutingKey_given_envelope_without_routing_key_it_will_return_empty_string(t *testing.T) {
e := WithRoutingKey(envelope.FromMessage("test message"), "test key")
routingKey := RoutingKey(e)
assert.Equal(t, "test key", routingKey)
}
func TestWithoutRoutingKey_will_remove_routing_key_header_on_envelope(t *testing.T) {
e := envelope.FromMessage("test message")
eWithRoutingKey := WithRoutingKey(e, "test key")
eWithoutRoutingKey := WithoutRoutingKey(eWithRoutingKey)
routingKey, found := eWithoutRoutingKey.LastHeader(routingKeyHeaderName)
assert.False(t, found)
assert.Equal(t, "", routingKey)
assert.True(t, eWithoutRoutingKey.Is(e))
}