-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
148 lines (120 loc) · 4.23 KB
/
config_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package runamqp
import (
"testing"
"github.com/mergermarket/run-amqp/helpers"
)
const defaultPrefetch = 10
func TestItDerivesConsumerExchanges(t *testing.T) {
logger := helpers.NewTestLogger(t)
c := NewConsumerConfig{
URL: testRabbitURI,
ExchangeName: "producer-stuff",
ExchangeType: Fanout,
Patterns: noPatterns,
Logger: logger,
RequeueTTL: 200,
RequeueLimit: testRequeueLimit,
ServiceName: "service",
Prefetch: defaultPrefetch,
}
consumerConfig := c.Config()
expectedQueueName := "producer-stuff-for-service"
if consumerConfig.queue.Name != expectedQueueName {
t.Error("Expected", expectedQueueName, consumerConfig.queue.Name)
}
expectededDLEName := "producer-stuff-for-service-dle"
if consumerConfig.exchange.DLE != expectededDLEName {
t.Error("Expected", expectededDLEName, "but got", consumerConfig.exchange.DLE)
}
expectedRetryNowExchangeName := "producer-stuff-for-service-retry-now"
if consumerConfig.exchange.RetryNow != expectedRetryNowExchangeName {
t.Error("Expected", expectedRetryNowExchangeName, "but got", consumerConfig.exchange.RetryNow)
}
expectedRetryLaterExchangeName := "producer-stuff-for-service-retry-200ms-later"
if consumerConfig.exchange.RetryLater != expectedRetryLaterExchangeName {
t.Error("Expected", expectedRetryLaterExchangeName, "but got", expectedRetryLaterExchangeName)
}
expectedDLQName := "producer-stuff-for-service-dlq"
if consumerConfig.queue.DLQ != expectedDLQName {
t.Error("Expected", expectedDLQName, "but got", consumerConfig.queue.DLQ)
}
expectedRetryLaterQueueName := "producer-stuff-for-service-retry-200ms-later"
if consumerConfig.queue.RetryLater != expectedRetryLaterQueueName {
t.Error("Expected", expectedRetryLaterQueueName, "but got", consumerConfig.queue.RetryLater)
}
if consumerConfig.queue.PrefetchCount != defaultPrefetch {
t.Error("Expected prefetch of", defaultPrefetch, "but got", consumerConfig.queue.PrefetchCount)
}
}
func TestItSetsPatternToHashWhenNoneSupplied(t *testing.T) {
logger := helpers.NewTestLogger(t)
c := NewConsumerConfig{
URL: testRabbitURI,
ExchangeName: "exchange",
ExchangeType: Fanout,
Patterns: noPatterns,
Logger: logger,
RequeueTTL: 200,
RequeueLimit: testRequeueLimit,
ServiceName: "service",
Prefetch: defaultPrefetch,
}
consumerConfig := c.Config()
if len(consumerConfig.queue.Patterns) != 1 {
t.Fatal("When there are no patterns supplied it should've put one in")
}
if consumerConfig.queue.Patterns[0] != "#" {
t.Error("Config should set the pattern to # (for catch all) if none are supplied but got", consumerConfig.queue.Patterns)
}
}
func TestItSetsPatternsOnQueue(t *testing.T) {
logger := helpers.NewTestLogger(t)
pattern := "pretty.pattern"
c := NewConsumerConfig{
URL: testRabbitURI,
ExchangeName: "exchange",
ExchangeType: Fanout,
Patterns: []string{pattern},
Logger: logger,
RequeueTTL: 200,
RequeueLimit: testRequeueLimit,
ServiceName: "service",
Prefetch: defaultPrefetch,
}
consumerConfig := c.Config()
if consumerConfig.queue.MaxPriority != 0 {
t.Error("Expected max priority to be set to 0 got", consumerConfig.queue.MaxPriority)
}
if len(consumerConfig.queue.Patterns) != 1 {
t.Fatal("There should be one pattern set")
}
if consumerConfig.queue.Patterns[0] != pattern {
t.Error("Unexpected pattern, expected", pattern, "but got", consumerConfig.queue.Patterns[0])
}
}
func TestItSetsMaxPriority(t *testing.T) {
logger := helpers.NewTestLogger(t)
pattern := "pretty.pattern"
c := NewConsumerConfig{
URL: testRabbitURI,
ExchangeName: "exchange",
ExchangeType: Fanout,
Patterns: []string{pattern},
Logger: logger,
RequeueTTL: 200,
RequeueLimit: testRequeueLimit,
ServiceName: "service",
Prefetch: defaultPrefetch,
MaxPriority: 7,
}
consumerConfig := c.Config()
if consumerConfig.queue.MaxPriority != 7 {
t.Error("Expected max priority to be set to 7 got", consumerConfig.queue.MaxPriority)
}
if len(consumerConfig.queue.Patterns) != 1 {
t.Fatal("There should be one pattern set")
}
if consumerConfig.queue.Patterns[0] != pattern {
t.Error("Unexpected pattern, expected", pattern, "but got", consumerConfig.queue.Patterns[0])
}
}