Skip to content

Commit 4feaa8b

Browse files
committed
Merge pull request libp2p#13 from masylum/patch-3
Do not allow undefined `peerInfo`
2 parents cd53344 + 0514b00 commit 4feaa8b

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
var Swarm = require('./swarm')
22

33
exports = module.exports = Swarm
4-
exports.singleton = new Swarm()

src/swarm.js

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ function Swarm (peerInfo) {
1111
throw new Error('Swarm must be called with new')
1212
}
1313

14+
if (!peerInfo) {
15+
throw new Error('You must provide a value for `peerInfo`')
16+
}
17+
1418
self.peerInfo = peerInfo
1519

1620
// peerIdB58: { conn: <conn> }

tests/swarm-test.js

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ process.on('uncaughtException', function (err) {
2424
console.log('Caught exception: ' + err)
2525
})
2626

27+
experiment('Without a peer', function () {
28+
test('it throws an exception', function (done) {
29+
expect(function () {
30+
var sw = new Swarm()
31+
sw.close()
32+
}).to.throw(Error)
33+
done()
34+
})
35+
})
36+
2737
experiment('Without a Stream Muxer', function () {
2838
experiment('tcp', function () {
2939
test('add the transport', function (done) {

0 commit comments

Comments
 (0)