Skip to content

Commit

Permalink
Merge pull request libp2p#13 from masylum/patch-3
Browse files Browse the repository at this point in the history
Do not allow undefined `peerInfo`
  • Loading branch information
daviddias committed Sep 26, 2015
2 parents cd53344 + 0514b00 commit 4feaa8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var Swarm = require('./swarm')

exports = module.exports = Swarm
exports.singleton = new Swarm()
4 changes: 4 additions & 0 deletions src/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function Swarm (peerInfo) {
throw new Error('Swarm must be called with new')
}

if (!peerInfo) {
throw new Error('You must provide a value for `peerInfo`')
}

self.peerInfo = peerInfo

// peerIdB58: { conn: <conn> }
Expand Down
10 changes: 10 additions & 0 deletions tests/swarm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err)
})

experiment('Without a peer', function () {
test('it throws an exception', function (done) {
expect(function () {
var sw = new Swarm()
sw.close()
}).to.throw(Error)
done()
})
})

experiment('Without a Stream Muxer', function () {
experiment('tcp', function () {
test('add the transport', function (done) {
Expand Down

0 comments on commit 4feaa8b

Please sign in to comment.