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

Implement all of the swarm API calls #253

Merged
merged 1 commit into from
Apr 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/api/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const cmds = require('../cmd-helpers')
module.exports = (send) => {
return {
peers: cmds.command(send, 'swarm/peers'),
connect: cmds.argCommand(send, 'swarm/connect')
connect: cmds.argCommand(send, 'swarm/connect'),
disconnect: cmds.argCommand(send, 'swarm/disconnect'),
addrs: cmds.command(send, 'swarm/addrs'),
localAddrs: cmds.command(send, 'swarm/addrs/local')
}
}
37 changes: 37 additions & 0 deletions test/api/swarm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,49 @@ describe('.swarm', () => {
done()
})

it('.swarm.disconnect', (done) => {
// Done in the 'after' segment
done()
})

it('.swarm.addrs', (done) => {
apiClients['a'].swarm.addrs((err, res) => {
expect(err).to.not.exist

expect(Object.keys(res.Addrs)).to.have.length.above(1)
done()
})
})

it('.swarm.localAddrs', (done) => {
apiClients['a'].swarm.localAddrs((err, res) => {
expect(err).to.not.exist

expect(res.Strings).to.have.length.above(1)
done()
})
})

describe('promise', () => {
it('.swarm.peers', () => {
return apiClients.a.swarm.peers()
.then((res) => {
expect(res.Strings).to.have.length.above(1)
})
})

it('.swarm.addrs', () => {
return apiClients['a'].swarm.addrs()
.then((res) => {
expect(Object.keys(res.Addrs)).to.have.length.above(1)
})
})

it('.swarm.localAddrs', () => {
return apiClients['a'].swarm.localAddrs()
.then((res) => {
expect(res.Strings).to.have.length.above(1)
})
})
})
})
21 changes: 20 additions & 1 deletion test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const apiAddrs = require('./tmp-disposable-nodes-addrs.json')
// a, b, c
global.apiClients = {}

const addrs = {}

function connectNodes (done) {
const addrs = {}
let counter = 0

function collectAddr (key, cb) {
Expand Down Expand Up @@ -47,6 +48,20 @@ function connectNodes (done) {
collectAddr('c', finish)
}

function disconnectNodes (done) {
global.apiClients.a.swarm.disconnect(addrs.b, (err) => {
if (err) {
throw err
}
global.apiClients.a.swarm.disconnect(addrs.c, (err) => {
if (err) {
throw err
}
done()
})
})
}

before(function (done) {
this.timeout(20000)

Expand All @@ -56,3 +71,7 @@ before(function (done) {

connectNodes(done)
})

after(function (done) {
disconnectNodes(done)
})