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

Commit 6effa19

Browse files
fix(swarm): fix cli commands and enable tests
1 parent 9cb9dc1 commit 6effa19

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

src/cli/commands/swarm/addrs.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@ module.exports = {
2020
if (err) {
2121
throw err
2222
}
23-
// TODO
23+
24+
ipfs.swarm.addrs((err, res) => {
25+
if (err) {
26+
throw err
27+
}
28+
29+
res.forEach((peer) => {
30+
const count = peer.multiaddrs.length
31+
console.log(`${peer.id.toB58String()} (${count})`)
32+
peer.multiaddrs.forEach((addr) => {
33+
const res = addr.decapsulate('ipfs').toString()
34+
console.log(`\t${res}`)
35+
})
36+
})
37+
})
2438
})
2539
}
2640
}

src/cli/commands/swarm/addrs/local.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ module.exports = {
2727
throw err
2828
}
2929

30-
res.Strings.forEach((addr) => {
31-
console.log(addr)
30+
res.forEach((addr) => {
31+
console.log(addr.toString())
3232
})
3333
})
3434
})

src/cli/commands/swarm/peers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ module.exports = {
2727
throw err
2828
}
2929

30-
res.Strings.forEach((addr) => {
31-
console.log(addr)
30+
res.forEach((addr) => {
31+
console.log(addr.toString())
3232
})
3333
})
3434
})

test/cli/test-swarm.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe('swarm', function () {
2626
expect(err).to.not.exist
2727
ipfs.id((err, identity) => {
2828
expect(err).to.not.exist
29-
ipfsAddr = `${identity.addresses[0]}/ipfs/${identity.id}`
29+
ipfsAddr = identity.addresses[0]
30+
console.log('addr', ipfsAddr)
3031
done()
3132
})
3233
})
@@ -51,18 +52,32 @@ describe('swarm', function () {
5152
})
5253
})
5354

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

64-
it.skip('peers', (done) => {
67+
it('peers', (done) => {
6568
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'swarm', 'peers'], {env})
69+
.run((err, stdout, exitcode) => {
70+
expect(err).to.not.exist
71+
expect(exitcode).to.equal(0)
72+
expect(stdout).to.be.eql([
73+
ipfsAddr
74+
])
75+
done()
76+
})
77+
})
78+
79+
it('addrs', (done) => {
80+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'swarm', 'addrs'], {env})
6681
.run((err, stdout, exitcode) => {
6782
expect(err).to.not.exist
6883
expect(exitcode).to.equal(0)
@@ -71,7 +86,7 @@ describe('swarm', function () {
7186
})
7287
})
7388

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

0 commit comments

Comments
 (0)