From 7143942fba9975e14798f5409466b8c505bb8e3e Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 16 Mar 2016 14:47:21 +0000 Subject: [PATCH] jsipfs swarm libp2p start and stop not fail on browser tests. separate browser and node.js swarm tests --- src/cli/commands/swarm/addrs.js | 21 ++++++++++++ src/cli/commands/swarm/addrs/local.js | 21 ++++++++++++ src/cli/commands/swarm/connect.js | 21 ++++++++++++ src/cli/commands/swarm/disconnect.js | 21 ++++++++++++ src/cli/commands/swarm/peers.js | 21 ++++++++++++ src/core/index.js | 8 +++-- src/http-api/routes/swarm.js | 46 +++++++++++++++++++++++++++ test/cli-tests/test-commands.js | 2 +- test/core-tests/test-bootstrap.js | 1 - test/core-tests/test-id.js | 1 - test/core-tests/test-swarm-node.js | 1 - test/core-tests/test-version.js | 1 - 12 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 src/cli/commands/swarm/addrs.js create mode 100644 src/cli/commands/swarm/addrs/local.js create mode 100644 src/cli/commands/swarm/connect.js create mode 100644 src/cli/commands/swarm/disconnect.js create mode 100644 src/cli/commands/swarm/peers.js create mode 100644 src/http-api/routes/swarm.js diff --git a/src/cli/commands/swarm/addrs.js b/src/cli/commands/swarm/addrs.js new file mode 100644 index 0000000000..ddb90dafa8 --- /dev/null +++ b/src/cli/commands/swarm/addrs.js @@ -0,0 +1,21 @@ +const Command = require('ronin').Command +const utils = require('../../utils') +const bs58 = require('bs58') +const debug = require('debug') +const log = debug('cli:object') +log.error = debug('cli:object:error') + +module.exports = Command.extend({ + desc: '', + + options: {}, + + run: () => { + utils.getIPFS((err, ipfs) => { + if (err) { + throw err + } + // TODO + }) + } +}) diff --git a/src/cli/commands/swarm/addrs/local.js b/src/cli/commands/swarm/addrs/local.js new file mode 100644 index 0000000000..680cc4fff7 --- /dev/null +++ b/src/cli/commands/swarm/addrs/local.js @@ -0,0 +1,21 @@ +const Command = require('ronin').Command +const utils = require('../../../utils') +const bs58 = require('bs58') +const debug = require('debug') +const log = debug('cli:object') +log.error = debug('cli:object:error') + +module.exports = Command.extend({ + desc: '', + + options: {}, + + run: () => { + utils.getIPFS((err, ipfs) => { + if (err) { + throw err + } + // TODO + }) + } +}) diff --git a/src/cli/commands/swarm/connect.js b/src/cli/commands/swarm/connect.js new file mode 100644 index 0000000000..ddb90dafa8 --- /dev/null +++ b/src/cli/commands/swarm/connect.js @@ -0,0 +1,21 @@ +const Command = require('ronin').Command +const utils = require('../../utils') +const bs58 = require('bs58') +const debug = require('debug') +const log = debug('cli:object') +log.error = debug('cli:object:error') + +module.exports = Command.extend({ + desc: '', + + options: {}, + + run: () => { + utils.getIPFS((err, ipfs) => { + if (err) { + throw err + } + // TODO + }) + } +}) diff --git a/src/cli/commands/swarm/disconnect.js b/src/cli/commands/swarm/disconnect.js new file mode 100644 index 0000000000..ddb90dafa8 --- /dev/null +++ b/src/cli/commands/swarm/disconnect.js @@ -0,0 +1,21 @@ +const Command = require('ronin').Command +const utils = require('../../utils') +const bs58 = require('bs58') +const debug = require('debug') +const log = debug('cli:object') +log.error = debug('cli:object:error') + +module.exports = Command.extend({ + desc: '', + + options: {}, + + run: () => { + utils.getIPFS((err, ipfs) => { + if (err) { + throw err + } + // TODO + }) + } +}) diff --git a/src/cli/commands/swarm/peers.js b/src/cli/commands/swarm/peers.js new file mode 100644 index 0000000000..ddb90dafa8 --- /dev/null +++ b/src/cli/commands/swarm/peers.js @@ -0,0 +1,21 @@ +const Command = require('ronin').Command +const utils = require('../../utils') +const bs58 = require('bs58') +const debug = require('debug') +const log = debug('cli:object') +log.error = debug('cli:object:error') + +module.exports = Command.extend({ + desc: '', + + options: {}, + + run: () => { + utils.getIPFS((err, ipfs) => { + if (err) { + throw err + } + // TODO + }) + } +}) diff --git a/src/core/index.js b/src/core/index.js index 08226abb5d..a22d25aaa0 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -323,11 +323,15 @@ function IPFS (repo) { libp2pNode.swarm.close(callback) }, swarm: { - peers: () => {}, + peers: (callback) => { + callback(null, []) + }, + // all the addrs we know addrs: notImpl, + localAddrs: notImpl, connect: notImpl, disconnect: notImpl, - filters: notImpl + filters: notImpl // TODO }, routing: {}, records: {}, diff --git a/src/http-api/routes/swarm.js b/src/http-api/routes/swarm.js new file mode 100644 index 0000000000..4ba5a083fb --- /dev/null +++ b/src/http-api/routes/swarm.js @@ -0,0 +1,46 @@ +const resources = require('./../resources') + +module.exports = (server) => { + const api = server.select('API') + + api.route({ + method: 'GET', + path: '/api/v0/swarm/addrs', + config: { + handler: resources.swarm.addrs.handler + } + }) + + api.route({ + method: 'GET', + path: '/api/v0/swarm/addrs/local', + config: { + handler: resources.swarm.localAddrs.handler + } + }) + + api.route({ + method: 'GET', + path: '/api/v0/swarm/connect', + config: { + handler: resources.swarm.connect + } + }) + + api.route({ + method: 'GET', + path: '/api/v0/swarm/disconnect', + config: { + handler: resources.swarm.disconnect + } + }) + + // TODO + // api.route({ + // method: 'GET', + // path: '/api/v0/swarm/filters', + // config: { + // handler: resources.swarm.disconnect + // } + // }) +} diff --git a/test/cli-tests/test-commands.js b/test/cli-tests/test-commands.js index 10a69fd824..d636d19bcf 100644 --- a/test/cli-tests/test-commands.js +++ b/test/cli-tests/test-commands.js @@ -9,7 +9,7 @@ describe('commands', () => { .run((err, stdout, exitcode) => { expect(err).to.not.exist expect(exitcode).to.equal(0) - expect(stdout.length).to.equal(40) + expect(stdout.length).to.equal(45) done() }) }) diff --git a/test/core-tests/test-bootstrap.js b/test/core-tests/test-bootstrap.js index c7cc803d03..7c874f5729 100644 --- a/test/core-tests/test-bootstrap.js +++ b/test/core-tests/test-bootstrap.js @@ -2,7 +2,6 @@ const expect = require('chai').expect -process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' const IPFS = require('../../src/core') describe('bootstrap', () => { diff --git a/test/core-tests/test-id.js b/test/core-tests/test-id.js index 6486a76afa..71bc38f56e 100644 --- a/test/core-tests/test-id.js +++ b/test/core-tests/test-id.js @@ -2,7 +2,6 @@ const expect = require('chai').expect -process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' const IPFS = require('../../src/core') describe('id', () => { diff --git a/test/core-tests/test-swarm-node.js b/test/core-tests/test-swarm-node.js index aaf073f6d0..f782a35466 100644 --- a/test/core-tests/test-swarm-node.js +++ b/test/core-tests/test-swarm-node.js @@ -2,7 +2,6 @@ const expect = require('chai').expect -process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' const IPFS = require('../../src/core') describe('swarm', () => { diff --git a/test/core-tests/test-version.js b/test/core-tests/test-version.js index da96ee4190..cb9f964d72 100644 --- a/test/core-tests/test-version.js +++ b/test/core-tests/test-version.js @@ -2,7 +2,6 @@ const expect = require('chai').expect -process.env.IPFS_PATH = process.cwd() + '/tests/repo-example' const IPFS = require('../../src/core') describe('version', () => {