-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
100 lines (81 loc) · 1.84 KB
/
test.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
const { test } = require('tap')
const Fastify = require('fastify')
const fastifyAmqp = require('./index')
const PORT_OK = 5672
const HOST_OK = 'localhost'
const HOST_INVALID = '1234'
const PROTOCOL_OK = 'amqp'
test('undefined connection', t => {
t.plan(3)
const app = build(t)
app.register(fastifyAmqp, {}).ready(err => {
t.equal(typeof err, typeof {})
t.assert(err instanceof Error)
t.notOk(app.amqp, 'Should not have amqp decorator')
})
})
test('invalid connection', t => {
t.plan(3)
const app = build(t)
app.register(fastifyAmqp, {
hostname: HOST_INVALID,
socket: {
timeout: 10000
}
}).ready(err => {
t.equal(typeof err, typeof {})
t.assert(err instanceof Error)
t.notOk(app.amqp, 'Should not have amqp decorator')
})
})
test('connection ok without send port', t => {
t.plan(3)
const app = build(t)
app.register(fastifyAmqp, {
hostname: HOST_OK
}).ready(err => {
t.error(err)
t.ok(app.amqp.connection)
t.ok(app.amqp.channel)
})
})
test('connection object', t => {
t.plan(3)
const app = build(t)
app.register(fastifyAmqp, {
hostname: HOST_OK,
port: PORT_OK
}).ready(err => {
t.error(err)
t.ok(app.amqp.connection)
t.ok(app.amqp.channel)
})
})
test('connection url', t => {
t.plan(3)
const app = build(t)
app.register(fastifyAmqp, {
url: `${PROTOCOL_OK}://${HOST_OK}:${PORT_OK}`
}).ready(err => {
t.error(err)
t.ok(app.amqp.connection)
t.ok(app.amqp.channel)
})
})
test('connection with protocol ok', t => {
t.plan(3)
const app = build(t)
app.register(fastifyAmqp, {
hostname: HOST_OK,
protocol: PROTOCOL_OK
}).ready(err => {
t.error(err)
t.ok(app.amqp.connection)
t.ok(app.amqp.channel)
})
})
function build (t) {
const app = Fastify()
t.teardown(app.close.bind(app))
return app
}