Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit c56fac7

Browse files
authored
Merge pull request #145 from vith/master
test: add test for ipfs.pubsub.publish with a binary (non-utf8) buffer
2 parents 9e9310b + ae704b5 commit c56fac7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/pubsub.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,46 @@ module.exports = (common) => {
382382
})
383383
})
384384

385+
it('round trips a non-utf8 binary buffer correctly', (done) => {
386+
const check = makeCheck(3, done)
387+
const expectedHex = 'a36161636179656162830103056164a16466666666f4'
388+
const buffer = Buffer.from(expectedHex, 'hex')
389+
390+
const sub1 = (msg) => {
391+
try {
392+
expect(msg.data.toString('hex')).to.be.eql(expectedHex)
393+
expect(msg.from).to.be.eql(ipfs2.peerId.id)
394+
check()
395+
} catch (err) {
396+
check(err)
397+
} finally {
398+
ipfs1.pubsub.unsubscribe(topic, sub1)
399+
}
400+
}
401+
402+
const sub2 = (msg) => {
403+
try {
404+
expect(msg.data.toString('hex')).to.be.eql(expectedHex)
405+
expect(msg.from).to.be.eql(ipfs2.peerId.id)
406+
check()
407+
} catch (err) {
408+
check(err)
409+
} finally {
410+
ipfs2.pubsub.unsubscribe(topic, sub2)
411+
}
412+
}
413+
414+
series([
415+
(cb) => ipfs1.pubsub.subscribe(topic, sub1, cb),
416+
(cb) => ipfs2.pubsub.subscribe(topic, sub2, cb),
417+
(cb) => waitForPeers(ipfs2, topic, [ipfs1.peerId.id], cb)
418+
], (err) => {
419+
expect(err).to.not.exist()
420+
421+
ipfs2.pubsub.publish(topic, buffer, check)
422+
})
423+
})
424+
385425
it('receive multiple messages', (done) => {
386426
const inbox1 = []
387427
const inbox2 = []

0 commit comments

Comments
 (0)