Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix(swarm): fix cli commands and enable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Sep 15, 2016
1 parent 9cb9dc1 commit 6effa19
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
16 changes: 15 additions & 1 deletion src/cli/commands/swarm/addrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@ module.exports = {
if (err) {
throw err
}
// TODO

ipfs.swarm.addrs((err, res) => {
if (err) {
throw err
}

res.forEach((peer) => {
const count = peer.multiaddrs.length
console.log(`${peer.id.toB58String()} (${count})`)
peer.multiaddrs.forEach((addr) => {
const res = addr.decapsulate('ipfs').toString()
console.log(`\t${res}`)
})
})
})
})
}
}
4 changes: 2 additions & 2 deletions src/cli/commands/swarm/addrs/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module.exports = {
throw err
}

res.Strings.forEach((addr) => {
console.log(addr)
res.forEach((addr) => {
console.log(addr.toString())
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/swarm/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module.exports = {
throw err
}

res.Strings.forEach((addr) => {
console.log(addr)
res.forEach((addr) => {
console.log(addr.toString())
})
})
})
Expand Down
25 changes: 20 additions & 5 deletions test/cli/test-swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('swarm', function () {
expect(err).to.not.exist
ipfs.id((err, identity) => {
expect(err).to.not.exist
ipfsAddr = `${identity.addresses[0]}/ipfs/${identity.id}`
ipfsAddr = identity.addresses[0]
console.log('addr', ipfsAddr)
done()
})
})
Expand All @@ -51,18 +52,32 @@ describe('swarm', function () {
})
})

// TODO revisit these once interface-ipfs-core over http-api are done
it.skip('connect', (done) => {
it('connect', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'swarm', 'connect', ipfsAddr], {env})
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
expect(stdout).to.be.eql([
`connect ${ipfsAddr} success`
])
done()
})
})

it.skip('peers', (done) => {
it('peers', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'swarm', 'peers'], {env})
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
expect(stdout).to.be.eql([
ipfsAddr
])
done()
})
})

it('addrs', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'swarm', 'addrs'], {env})
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
Expand All @@ -71,7 +86,7 @@ describe('swarm', function () {
})
})

it.skip('addrs local', (done) => {
it('addrs local', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'swarm', 'addrs', 'local'], {env})
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
Expand Down

0 comments on commit 6effa19

Please sign in to comment.