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

Commit

Permalink
test: add test for ipfs.pubsub.publish with a binary (non-utf8) buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
vith committed Jun 21, 2017
1 parent 9e9310b commit 2a1445a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,46 @@ module.exports = (common) => {
})
})

it('round trips a non-utf8 binary buffer correctly', (done) => {
const check = makeCheck(3, done)
const expectedHex = 'a36161636179656162830103056164a16466666666f4'
const buffer = Buffer.from(expectedHex, 'hex')

const sub1 = (msg) => {
try {
expect(msg.data.toString('hex')).to.be.eql(expectedHex)
expect(msg.from).to.be.eql(ipfs2.peerId.id)
check()
} catch (e) {
check(e)
} finally {
ipfs1.pubsub.unsubscribe(topic, sub1)
}
}

const sub2 = (msg) => {
try {
expect(msg.data.toString('hex')).to.be.eql(expectedHex)
expect(msg.from).to.be.eql(ipfs2.peerId.id)
check()
} catch (e) {
check(e)
} finally {
ipfs2.pubsub.unsubscribe(topic, sub2)
}
}

series([
(cb) => ipfs1.pubsub.subscribe(topic, sub1, cb),
(cb) => ipfs2.pubsub.subscribe(topic, sub2, cb),
(cb) => waitForPeers(ipfs2, topic, [ipfs1.peerId.id], cb),
], (err) => {
expect(err).to.not.exist()

ipfs2.pubsub.publish(topic, buffer, check)
})
})

it('receive multiple messages', (done) => {
const inbox1 = []
const inbox2 = []
Expand Down

0 comments on commit 2a1445a

Please sign in to comment.