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

Commit 7143942

Browse files
committed
jsipfs swarm
libp2p start and stop not fail on browser tests. separate browser and node.js swarm tests
1 parent 6f2d879 commit 7143942

File tree

12 files changed

+158
-7
lines changed

12 files changed

+158
-7
lines changed

src/cli/commands/swarm/addrs.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Command = require('ronin').Command
2+
const utils = require('../../utils')
3+
const bs58 = require('bs58')
4+
const debug = require('debug')
5+
const log = debug('cli:object')
6+
log.error = debug('cli:object:error')
7+
8+
module.exports = Command.extend({
9+
desc: '',
10+
11+
options: {},
12+
13+
run: () => {
14+
utils.getIPFS((err, ipfs) => {
15+
if (err) {
16+
throw err
17+
}
18+
// TODO
19+
})
20+
}
21+
})

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

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Command = require('ronin').Command
2+
const utils = require('../../../utils')
3+
const bs58 = require('bs58')
4+
const debug = require('debug')
5+
const log = debug('cli:object')
6+
log.error = debug('cli:object:error')
7+
8+
module.exports = Command.extend({
9+
desc: '',
10+
11+
options: {},
12+
13+
run: () => {
14+
utils.getIPFS((err, ipfs) => {
15+
if (err) {
16+
throw err
17+
}
18+
// TODO
19+
})
20+
}
21+
})

src/cli/commands/swarm/connect.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Command = require('ronin').Command
2+
const utils = require('../../utils')
3+
const bs58 = require('bs58')
4+
const debug = require('debug')
5+
const log = debug('cli:object')
6+
log.error = debug('cli:object:error')
7+
8+
module.exports = Command.extend({
9+
desc: '',
10+
11+
options: {},
12+
13+
run: () => {
14+
utils.getIPFS((err, ipfs) => {
15+
if (err) {
16+
throw err
17+
}
18+
// TODO
19+
})
20+
}
21+
})

src/cli/commands/swarm/disconnect.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Command = require('ronin').Command
2+
const utils = require('../../utils')
3+
const bs58 = require('bs58')
4+
const debug = require('debug')
5+
const log = debug('cli:object')
6+
log.error = debug('cli:object:error')
7+
8+
module.exports = Command.extend({
9+
desc: '',
10+
11+
options: {},
12+
13+
run: () => {
14+
utils.getIPFS((err, ipfs) => {
15+
if (err) {
16+
throw err
17+
}
18+
// TODO
19+
})
20+
}
21+
})

src/cli/commands/swarm/peers.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Command = require('ronin').Command
2+
const utils = require('../../utils')
3+
const bs58 = require('bs58')
4+
const debug = require('debug')
5+
const log = debug('cli:object')
6+
log.error = debug('cli:object:error')
7+
8+
module.exports = Command.extend({
9+
desc: '',
10+
11+
options: {},
12+
13+
run: () => {
14+
utils.getIPFS((err, ipfs) => {
15+
if (err) {
16+
throw err
17+
}
18+
// TODO
19+
})
20+
}
21+
})

src/core/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,15 @@ function IPFS (repo) {
323323
libp2pNode.swarm.close(callback)
324324
},
325325
swarm: {
326-
peers: () => {},
326+
peers: (callback) => {
327+
callback(null, [])
328+
},
329+
// all the addrs we know
327330
addrs: notImpl,
331+
localAddrs: notImpl,
328332
connect: notImpl,
329333
disconnect: notImpl,
330-
filters: notImpl
334+
filters: notImpl // TODO
331335
},
332336
routing: {},
333337
records: {},

src/http-api/routes/swarm.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const resources = require('./../resources')
2+
3+
module.exports = (server) => {
4+
const api = server.select('API')
5+
6+
api.route({
7+
method: 'GET',
8+
path: '/api/v0/swarm/addrs',
9+
config: {
10+
handler: resources.swarm.addrs.handler
11+
}
12+
})
13+
14+
api.route({
15+
method: 'GET',
16+
path: '/api/v0/swarm/addrs/local',
17+
config: {
18+
handler: resources.swarm.localAddrs.handler
19+
}
20+
})
21+
22+
api.route({
23+
method: 'GET',
24+
path: '/api/v0/swarm/connect',
25+
config: {
26+
handler: resources.swarm.connect
27+
}
28+
})
29+
30+
api.route({
31+
method: 'GET',
32+
path: '/api/v0/swarm/disconnect',
33+
config: {
34+
handler: resources.swarm.disconnect
35+
}
36+
})
37+
38+
// TODO
39+
// api.route({
40+
// method: 'GET',
41+
// path: '/api/v0/swarm/filters',
42+
// config: {
43+
// handler: resources.swarm.disconnect
44+
// }
45+
// })
46+
}

test/cli-tests/test-commands.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('commands', () => {
99
.run((err, stdout, exitcode) => {
1010
expect(err).to.not.exist
1111
expect(exitcode).to.equal(0)
12-
expect(stdout.length).to.equal(40)
12+
expect(stdout.length).to.equal(45)
1313
done()
1414
})
1515
})

test/core-tests/test-bootstrap.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const expect = require('chai').expect
44

5-
process.env.IPFS_PATH = process.cwd() + '/tests/repo-example'
65
const IPFS = require('../../src/core')
76

87
describe('bootstrap', () => {

test/core-tests/test-id.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const expect = require('chai').expect
44

5-
process.env.IPFS_PATH = process.cwd() + '/tests/repo-example'
65
const IPFS = require('../../src/core')
76

87
describe('id', () => {

test/core-tests/test-swarm-node.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const expect = require('chai').expect
44

5-
process.env.IPFS_PATH = process.cwd() + '/tests/repo-example'
65
const IPFS = require('../../src/core')
76

87
describe('swarm', () => {

test/core-tests/test-version.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const expect = require('chai').expect
44

5-
process.env.IPFS_PATH = process.cwd() + '/tests/repo-example'
65
const IPFS = require('../../src/core')
76

87
describe('version', () => {

0 commit comments

Comments
 (0)