/
index.spec.js
328 lines (286 loc) · 9.21 KB
/
index.spec.js
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/* eslint-disable max-lines, no-magic-numbers */
/* eslint-env mocha */
const parser = require( "./index" );
const data = require( "./index.spec.json" );
const { assert } = testHelpers;
describe( "Topology Parser", () => {
let topology;
context( "parsing exchanges separately", () => {
beforeEach( () => {
topology = parser.parse( data[ "exchanges-only" ] );
} );
it( "should parse all exchanges defined", () => {
assert.deepEqual( topology.exchanges, {
fat: {
name: "defined.exchange",
type: "fanout",
durable: true,
internal: true,
autoDelete: true,
alternateExchange: "alternate.exchange",
arguments: {
custom: "value",
canonical: true,
unsupported: "value"
}
},
minimal: {
name: "minimal",
type: "fanout"
}
} );
} );
it( "should not contain any extra properties", () => {
assert.notProperty( topology.exchanges.fat, "unsupported" );
} );
} );
context( "parsing queues separately", () => {
beforeEach( () => {
topology = parser.parse( data[ "queues-only" ] );
} );
it( "should parse the normal queue definition", () => {
assert.deepEqual( topology.queues[ "defined.queue" ], {
name: "defined.queue",
exclusive: true,
durable: true,
autoDelete: true,
expires: 600,
maxLength: 100,
maxPriority: 1,
messageTtl: 500,
arguments: {
custom: "value",
unsupported: "value"
}
} );
} );
it( "should parse the dead-letter queue definition", () => {
assert.deepEqual( topology.queues[ "deadletter.queue" ], {
name: "deadletter.queue",
deadLetterExchange: "dlx",
deadLetterRoutingKey: "#"
} );
} );
it( "should not parse any extra properties", () => {
assert.notProperty( topology.queues[ "defined.queue" ], "unsupported" );
} );
} );
context( "parsing bindings separately", () => {
context( "given normal, unique bindings", () => {
beforeEach( () => {
topology = parser.parse( data[ "bindings-only" ] );
} );
it( "should parse the queue binding", () => {
assert.lengthOf( topology.bindings.queues, 2 );
assert.deepEqual( topology.bindings.queues[ 0 ], {
exchange: "target.exchange",
target: "target.queue",
pattern: "#"
} );
assert.deepEqual( topology.bindings.queues[ 1 ], {
exchange: "target.exchange",
target: "target.queue",
pattern: "*.message"
} );
} );
it( "should parse the exchange binding", () => {
assert.lengthOf( topology.bindings.exchanges, 1 );
assert.deepEqual( topology.bindings.exchanges[ 0 ], {
exchange: "target.exchange",
target: "target.exchange.topic",
pattern: ""
} );
} );
} );
context( "given duplicate bindings", () => {
beforeEach( () => {
topology = parser.parse( data[ "bindings-only-duplicates" ] );
} );
it( "should parse only one binding", () => {
assert.lengthOf( topology.bindings.queues, 1 );
} );
} );
context( "given root bindings referencing undefined queues", () => {
it( "should throw an error", () => {
assert.throws( () => parser.parse( data[ "bindings-missing-queues" ] ) );
} );
} );
context( "given root bindings referencing undefined exchanges", () => {
it( "should throw an error", () => {
assert.throws( () => parser.parse( data[ "bindings-missing-exchanges" ] ) );
} );
} );
} );
context( "parsing embedded alternate exchanges", () => {
beforeEach( () => {
topology = parser.parse( data[ "embedded-alt-exchange" ] );
} );
it( "should create the alternate exchange", () => {
assert.deepEqual( topology.exchanges[ "alternate.exchange" ], {
name: "alternate.exchange",
type: "fanout",
durable: true,
autoDelete: false
} );
} );
} );
context( "parsing embedded dead letter exchanges", () => {
beforeEach( () => {
topology = parser.parse( data[ "embedded-deadletter-exchange" ] );
} );
it( "should create the dead-letter exchange", () => {
assert.deepEqual( topology.exchanges[ "defined.dlx" ], {
name: "defined.dlx",
type: "fanout"
} );
} );
} );
context( "parsing embedded queue bindings", () => {
beforeEach( () => {
topology = parser.parse( data[ "embedded-queue-bindings" ] );
} );
it( "should create the embedded queue from the binding", () => {
assert.deepProperty( topology.queues, "defined\\.queue" );
assert.deepEqual( topology.queues[ "defined.queue" ], {
name: "defined.queue",
durable: true,
deadLetterExchange: "defined.dlx",
deadLetterRoutingKey: undefined
} );
} );
it( "should create the embedded dead-letter exchange", () => {
assert.deepProperty( topology.exchanges, "defined\\.dlx" );
assert.deepEqual( topology.exchanges[ "defined.dlx" ], {
name: "defined.dlx",
type: "fanout"
} );
} );
it( "should create the queue binding for the embedded queue", () => {
assert.deepEqual( topology.bindings.queues[ 0 ], {
exchange: "defined.exchange",
target: "defined.queue",
pattern: "*.message"
} );
} );
it( "should create the queue binding for the referenced queue", async () => {
assert.deepEqual( topology.bindings.queues[ 1 ], {
exchange: "defined.exchange",
target: "referenced.queue",
pattern: "#"
} );
} );
} );
context( "parsing embedded exchange bindings", () => {
beforeEach( () => {
topology = parser.parse( data[ "embedded-exchange-bindings" ] );
} );
it( "should create the embedded exchange from the binding", () => {
assert.deepProperty( topology.exchanges, "defined\\.exchange\\.topic" );
assert.deepEqual( topology.exchanges[ "defined.exchange.topic" ], {
name: "defined.exchange.topic",
type: "topic",
durable: true
} );
} );
it( "should create the exchange binding for the embedded exchange", () => {
assert.deepEqual( topology.bindings.exchanges[ 0 ], {
exchange: "defined.exchange",
target: "defined.exchange.topic",
pattern: "#"
} );
} );
it( "should create the exchange binding for the reference", async () => {
assert.deepEqual( topology.bindings.exchanges[ 1 ], {
exchange: "defined.exchange",
target: "referenced.exchange",
pattern: "#"
} );
} );
} );
context( "parsing subscriptions", () => {
beforeEach( () => {
topology = parser.parse( data.subscriptions );
} );
it( "should create the subscription exchange", () => {
assert.deepProperty( topology.exchanges, "subscription\\.exchange" );
assert.deepEqual( topology.exchanges[ "subscription.exchange" ], {
name: "subscription.exchange",
type: "fanout"
} );
} );
it( "should create the topic exchange", () => {
assert.deepProperty( topology.exchanges, "topic\\.exchange" );
assert.deepEqual( topology.exchanges[ "topic.exchange" ], {
name: "topic.exchange",
type: "topic"
} );
} );
it( "should create the exchange bindings", () => {
assert.deepEqual( topology.bindings.exchanges[ 0 ], {
exchange: "topic.exchange",
target: "subscription.exchange",
pattern: "*.one"
} );
assert.deepEqual( topology.bindings.exchanges[ 1 ], {
exchange: "topic.exchange",
target: "subscription.exchange",
pattern: "*.two"
} );
} );
} );
context( "parsing subscriptions with embedded exchanges", () => {
beforeEach( () => {
topology = parser.parse( data[ "embedded-subscriptions" ] );
} );
it( "should create the subscription exchange", () => {
assert.deepProperty( topology.exchanges, "subscription\\.exchange" );
assert.deepEqual( topology.exchanges[ "subscription.exchange" ], {
name: "subscription.exchange",
type: "fanout"
} );
} );
it( "should create the topic exchange", () => {
assert.deepProperty( topology.exchanges, "topic\\.one" );
assert.deepEqual( topology.exchanges[ "topic.one" ], {
name: "topic.one",
type: "topic"
} );
} );
it( "should create the exchange bindings", () => {
assert.deepEqual( topology.bindings.exchanges[ 0 ], {
exchange: "topic.one",
target: "subscription.exchange",
pattern: "*.one"
} );
assert.deepEqual( topology.bindings.exchanges[ 1 ], {
exchange: "topic.one",
target: "subscription.exchange",
pattern: "*.two"
} );
} );
} );
context( "named primitives", () => {
beforeEach( () => {
topology = parser.parse( data[ "named-primitives" ] );
} );
it( "should create an index-named queue", () => {
assert.deepProperty( topology.queues, "delivery" );
assert.deepEqual( topology.queues.delivery, { name: "defined.queue" } );
} );
it( "should create an index-named exchange", () => {
assert.deepProperty( topology.exchanges, "subscription" );
assert.deepEqual( topology.exchanges.subscription, { name: "defined.exchange", type: "topic" } );
} );
it( "should create an index-named nested exchange", () => {
assert.deepProperty( topology.exchanges, "nested" );
assert.deepEqual( topology.exchanges.nested, { name: "nested.exchange", type: "fanout" } );
} );
it( "should create an index-named queue for the embedded queue", () => {
assert.deepProperty( topology.queues, "ingress" );
assert.deepEqual( topology.queues.ingress, { name: "ingress.queue" } );
} );
it( "should not create an index-named queue for the referenced simple queue", () => {
assert.notProperty( topology.queues, "simple" );
} );
} );
} );