-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
73 lines (59 loc) · 1.25 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
var test = require('tape').test
, graftBroker = require('./')
test('basic', function(t) {
t.plan(1)
var broker = graftBroker()
, updates = broker.ReadChannel()
updates.on('data', function(data) {
t.deepEqual(data, {
cmd: 'publish'
, topic: 'hello'
, hello: 'world'
})
})
broker.write({
cmd: 'subscribe'
, topic: 'hello'
, messages: updates
})
broker.write({
cmd: 'publish'
, topic: 'hello'
, hello: 'world'
})
})
test('status ok', function(t) {
t.plan(1)
var broker = graftBroker()
, updates = broker.ReadChannel()
, ret = broker.ReadChannel()
ret.on('data', function(data) {
t.deepEqual(data, {
status: 'subscribed'
, topic: 'hello'
})
})
broker.write({
cmd: 'subscribe'
, topic: 'hello'
, messages: updates
, ret: ret
})
})
test('status failed because of no topic', function(t) {
t.plan(1)
var broker = graftBroker()
, updates = broker.ReadChannel()
, ret = broker.ReadChannel()
ret.on('data', function(data) {
t.deepEqual(data, {
status: 'not subscribed'
, reason: 'missing topic'
})
})
broker.write({
cmd: 'subscribe'
, messages: updates
, ret: ret
})
})