diff --git a/package.json b/package.json index 53abbe1fe..8dc0ea739 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,8 @@ "glob": "^7.1.2", "ipfs-block": "~0.7.1", "ipfs-unixfs": "~0.1.15", - "ipld-dag-cbor": "~0.12.0", - "ipld-dag-pb": "~0.14.4", + "ipld-dag-cbor": "~0.12.1", + "ipld-dag-pb": "~0.14.5", "is-ipfs": "~0.3.2", "is-pull-stream": "0.0.0", "is-stream": "^1.1.0", @@ -48,7 +48,7 @@ "multihashes": "~0.4.13", "ndjson": "^1.5.0", "once": "^1.4.0", - "peer-id": "~0.10.7", + "peer-id": "~0.11.0", "peer-info": "~0.14.1", "promisify-es6": "^1.0.3", "pull-defer": "~0.2.2", @@ -74,13 +74,13 @@ "aegir": "^14.0.0", "browser-process-platform": "~0.1.1", "chai": "^4.1.2", - "cross-env": "^5.1.6", + "cross-env": "^5.2.0", "dirty-chai": "^2.0.1", - "eslint-plugin-react": "^7.9.1", + "eslint-plugin-react": "^7.10.0", "go-ipfs-dep": "~0.4.15", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.69.1", - "ipfsd-ctl": "~0.37.3", + "interface-ipfs-core": "~0.71.0", + "ipfsd-ctl": "~0.37.5", "pull-stream": "^3.6.8", "socket.io": "^2.1.1", "socket.io-client": "^2.1.1", diff --git a/src/dag/put.js b/src/dag/put.js index c0c2f211a..636d39ae4 100644 --- a/src/dag/put.js +++ b/src/dag/put.js @@ -5,54 +5,67 @@ const dagCBOR = require('ipld-dag-cbor') const promisify = require('promisify-es6') const CID = require('cids') const multihash = require('multihashes') -const setImmediate = require('async/setImmediate') const SendOneFile = require('../utils/send-one-file') -function noop () {} - module.exports = (send) => { const sendOneFile = SendOneFile(send, 'dag/put') return promisify((dagNode, options, callback) => { if (typeof options === 'function') { - return setImmediate(() => callback(new Error('no options were passed'))) + callback = options } - callback = callback || noop + options = options || {} - let hashAlg = options.hash || 'sha2-256' - let format - let inputEnc + if (options.hash) { + options.hashAlg = options.hash + delete options.hash + } - if (options.cid && CID.isCID(options.cid)) { - format = options.cid.codec - hashAlg = multihash.decode(options.cid.multihash).name - prepare() - } else if (options.format) { - format = options.format - prepare() - } else { - callback(new Error('Invalid arguments')) + if (options.cid && (options.format || options.hashAlg)) { + return callback(new Error('Can\'t put dag node. Please provide either `cid` OR `format` and `hash` options.')) + } else if ((options.format && !options.hashAlg) || (!options.format && options.hashAlg)) { + return callback(new Error('Can\'t put dag node. Please provide `format` AND `hash` options.')) } - function prepare () { - inputEnc = 'raw' + if (options.cid) { + let cid - if (format === 'dag-cbor') { - dagCBOR.util.serialize(dagNode, finalize) - } - if (format === 'dag-pb') { - dagPB.util.serialize(dagNode, finalize) + try { + cid = new CID(options.cid) + } catch (err) { + return callback(err) } + + options.format = cid.codec + options.hashAlg = multihash.decode(cid.multihash).name + delete options.cid + } + + const optionDefaults = { + format: 'dag-cbor', + hashAlg: 'sha2-256', + inputEnc: 'raw' + } + + options = Object.assign(optionDefaults, options) + + if (options.format === 'dag-cbor') { + dagCBOR.util.serialize(dagNode, finalize) + } else if (options.format === 'dag-pb') { + dagPB.util.serialize(dagNode, finalize) + } else { + // FIXME Hopefully already serialized...can we use IPLD to serialise instead? + finalize(null, dagNode) } function finalize (err, serialized) { if (err) { return callback(err) } const sendOptions = { qs: { - hash: hashAlg, - format: format, - 'input-enc': inputEnc + hash: options.hashAlg, + format: options.format, + 'input-enc': options.inputEnc } } sendOneFile(serialized, sendOptions, (err, result) => { diff --git a/test/interface.spec.js b/test/interface.spec.js new file mode 100644 index 000000000..5f169433f --- /dev/null +++ b/test/interface.spec.js @@ -0,0 +1,246 @@ +/* eslint-env mocha */ +'use strict' + +const tests = require('interface-ipfs-core') +const isNode = require('detect-node') +const CommonFactory = require('./utils/interface-common-factory') +const IPFSApi = require('../src') +const isWindows = process.platform && process.platform === 'win32' + +describe('interface-ipfs-core tests', () => { + const defaultCommonFactory = CommonFactory.create() + + tests.bitswap(defaultCommonFactory, { + skip: [ + // bitswap.stat + { + name: 'should not get bitswap stats when offline', + reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078' + }, + // bitswap.wantlist + { + name: 'should not get the wantlist when offline', + reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078' + }, + // bitswap.unwant + { + name: 'should remove a key from the wantlist', + reason: 'FIXME why is this skipped?' + }, + { + name: 'should not remove a key from the wantlist when offline', + reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078' + } + ] + }) + + tests.block(defaultCommonFactory) + + tests.bootstrap(defaultCommonFactory) + + tests.config(defaultCommonFactory, { + skip: [ + // config.replace + { + name: 'replace', + reason: 'FIXME Waiting for fix on go-ipfs https://github.com/ipfs/js-ipfs-api/pull/307#discussion_r69281789 and https://github.com/ipfs/go-ipfs/issues/2927' + } + ] + }) + + tests.dag(defaultCommonFactory, { + skip: [ + // dag.tree + { + name: 'tree', + reason: 'TODO vmx 2018-02-22: Currently the tree API is not exposed in go-ipfs' + }, + // dag.get: + { + name: 'should get a dag-pb node local value', + reason: 'FIXME vmx 2018-02-22: Currently not supported in go-ipfs, it might be possible once https://github.com/ipfs/go-ipfs/issues/4728 is done' + }, + { + name: 'should get dag-pb value via dag-cbor node', + reason: 'FIXME vmx 2018-02-22: Currently not supported in go-ipfs, it might be possible once https://github.com/ipfs/go-ipfs/issues/4728 is done' + }, + { + name: 'should get by CID string + path', + reason: 'FIXME vmx 2018-02-22: Currently not supported in go-ipfs, it might be possible once https://github.com/ipfs/go-ipfs/issues/4728 is done' + } + ] + }) + + tests.dht(defaultCommonFactory, { + skip: [ + // dht.findpeer + { + name: 'should fail to find other peer if peer does not exist', + reason: 'FIXME checking what is exactly go-ipfs returning https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090' + }, + // dht.findprovs + { + name: 'should provide from one node and find it through another node', + reason: 'FIXME go-ipfs endpoint doesn\'t conform with the others https://github.com/ipfs/go-ipfs/issues/5047' + }, + // dht.get + { + name: 'should get a value after it was put on another node', + reason: 'FIXME go-ipfs errors with Error: key was not found (type 6) https://github.com/ipfs/go-ipfs/issues/3862' + } + ] + }) + + tests.files(defaultCommonFactory, { + skip: [ + // files.add + isNode ? null : { + name: 'should add a nested directory as array of tupples', + reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339' + }, + isNode ? null : { + name: 'should add a nested directory as array of tupples with progress', + reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339' + }, + // files.addPullStream + isNode ? null : { + name: 'should add pull stream of valid files and dirs', + reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339' + }, + // files.addReadableStream + isNode ? null : { + name: 'should add readable stream of valid files and dirs', + reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339' + }, + // files.catPullStream + { + name: 'should export a chunk of a file', + reason: 'TODO not implemented in go-ipfs yet' + }, + { + name: 'should export a chunk of a file in a Pull Stream', + reason: 'TODO not implemented in go-ipfs yet' + }, + { + name: 'should export a chunk of a file in a Readable Stream', + reason: 'TODO not implemented in go-ipfs yet' + }, + // files.get + isNode ? null : { + name: 'should get a directory', + reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339' + } + ] + }) + + tests.key(defaultCommonFactory, { + skip: [ + // key.export + { + name: 'export', + reason: 'TODO not implemented in go-ipfs yet' + }, + // key.import + { + name: 'import', + reason: 'TODO not implemented in go-ipfs yet' + } + ] + }) + + tests.ls(defaultCommonFactory, { + skip: [ + // lsPullStream + isNode ? null : { + name: 'should pull stream ls with a base58 encoded CID', + reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339' + }, + // lsReadableStream + isNode ? null : { + name: 'should readable stream ls with a base58 encoded CID', + reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339' + }, + // ls + isNode ? null : { + name: 'should ls with a base58 encoded CID', + reason: 'FIXME https://github.com/ipfs/js-ipfs-api/issues/339' + } + ] + }) + + tests.miscellaneous(defaultCommonFactory, { + skip: [ + // stop + { + name: 'should stop the node', + reason: 'FIXME go-ipfs returns an error https://github.com/ipfs/go-ipfs/issues/4078' + } + ] + }) + + tests.object(defaultCommonFactory) + + tests.pin(defaultCommonFactory) + + tests.ping(defaultCommonFactory) + + tests.pubsub(CommonFactory.create({ + spawnOptions: { + args: ['--enable-pubsub-experiment'], + initOptions: { bits: 1024 } + } + }), { + skip: isNode ? [ + // pubsub.subscribe + isWindows ? { + name: 'should send/receive 100 messages', + reason: 'FIXME https://github.com/ipfs/interface-ipfs-core/pull/188#issuecomment-354673246 and https://github.com/ipfs/go-ipfs/issues/4778' + } : null, + isWindows ? { + name: 'should receive multiple messages', + reason: 'FIXME https://github.com/ipfs/interface-ipfs-core/pull/188#issuecomment-354673246 and https://github.com/ipfs/go-ipfs/issues/4778' + } : null + ] : { + reason: 'FIXME pubsub is not supported in the browser https://github.com/ipfs/js-ipfs-api/issues/518' + } + }) + + tests.repo(defaultCommonFactory) + + tests.stats(defaultCommonFactory) + + tests.swarm(CommonFactory.create({ + createSetup ({ ipfsFactory, nodes }) { + return callback => { + callback(null, { + spawnNode (repoPath, config, cb) { + if (typeof repoPath === 'function') { + cb = repoPath + repoPath = undefined + } + + if (typeof config === 'function') { + cb = config + config = undefined + } + + const spawnOptions = { repoPath, config, initOptions: { bits: 1024 } } + + ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) + } + } + })) + + tests.types(defaultCommonFactory, { skip: { reason: 'FIXME currently failing' } }) + + tests.util(defaultCommonFactory, { skip: { reason: 'FIXME currently failing' } }) +}) diff --git a/test/interface/bitswap.spec.js b/test/interface/bitswap.spec.js deleted file mode 100644 index 82eaacb6d..000000000 --- a/test/interface/bitswap.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.bitswap(common) diff --git a/test/interface/block.spec.js b/test/interface/block.spec.js deleted file mode 100644 index 180f17a04..000000000 --- a/test/interface/block.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.block(common) diff --git a/test/interface/bootstrap.spec.js b/test/interface/bootstrap.spec.js deleted file mode 100644 index caea5856e..000000000 --- a/test/interface/bootstrap.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.bootstrap(common) diff --git a/test/interface/config.spec.js b/test/interface/config.spec.js deleted file mode 100644 index aeb4a6a9a..000000000 --- a/test/interface/config.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.config(common) diff --git a/test/interface/dag.spec.js b/test/interface/dag.spec.js deleted file mode 100644 index 6c68680e7..000000000 --- a/test/interface/dag.spec.js +++ /dev/null @@ -1,34 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn((err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.dag(common) diff --git a/test/interface/dht.spec.js b/test/interface/dht.spec.js deleted file mode 100644 index 2b324cb99..000000000 --- a/test/interface/dht.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.dht(common) diff --git a/test/interface/files-mfs.spec.js b/test/interface/files-mfs.spec.js deleted file mode 100644 index 6de81af4e..000000000 --- a/test/interface/files-mfs.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.filesMFS(common) diff --git a/test/interface/files.spec.js b/test/interface/files.spec.js deleted file mode 100644 index c99f768a6..000000000 --- a/test/interface/files.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.files(common) diff --git a/test/interface/key.spec.js b/test/interface/key.spec.js deleted file mode 100644 index 56f6e6893..000000000 --- a/test/interface/key.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.key(common) diff --git a/test/interface/miscellaneous.spec.js b/test/interface/miscellaneous.spec.js deleted file mode 100644 index c890a2fa3..000000000 --- a/test/interface/miscellaneous.spec.js +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - // No need to stop, because the test suite does a 'stop' test. - // parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - callback() - } -} - -test.generic(common) diff --git a/test/interface/object.spec.js b/test/interface/object.spec.js deleted file mode 100644 index e76c45673..000000000 --- a/test/interface/object.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.object(common) diff --git a/test/interface/pin.spec.js b/test/interface/pin.spec.js deleted file mode 100644 index e56bc413d..000000000 --- a/test/interface/pin.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.pin(common) diff --git a/test/interface/ping.spec.js b/test/interface/ping.spec.js deleted file mode 100644 index 910bf3820..000000000 --- a/test/interface/ping.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.ping(common) diff --git a/test/interface/pubsub.spec.js b/test/interface/pubsub.spec.js deleted file mode 100644 index 154fec2f4..000000000 --- a/test/interface/pubsub.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const isNode = require('detect-node') - -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -if (isNode) { - const nodes = [] - const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 }, args: ['--enable-pubsub-experiment'] }, - (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } - } - - test.pubsub(common) -} diff --git a/test/interface/repo.spec.js b/test/interface/repo.spec.js deleted file mode 100644 index c6966772d..000000000 --- a/test/interface/repo.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.repo(common) diff --git a/test/interface/stats.spec.js b/test/interface/stats.spec.js deleted file mode 100644 index eee30ad98..000000000 --- a/test/interface/stats.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.stats(common) diff --git a/test/interface/swarm.spec.js b/test/interface/swarm.spec.js deleted file mode 100644 index 56b9cbe41..000000000 --- a/test/interface/swarm.spec.js +++ /dev/null @@ -1,42 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFSApi = require('../../src') -const f = require('../utils/factory') - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (repoPath, config, cb) => { - if (typeof repoPath === 'function') { - cb = repoPath - repoPath = undefined - } - - if (typeof config === 'function') { - cb = config - config = undefined - } - - f.spawn({ repoPath, config, initOptions: { bits: 1024 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, IPFSApi(_ipfsd.apiAddr)) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.swarm(common) diff --git a/test/util.spec.js b/test/util.spec.js index 83e67e8de..52ce9ebd7 100644 --- a/test/util.spec.js +++ b/test/util.spec.js @@ -160,7 +160,9 @@ describe('.util', () => { .then(out => expectTimeout(ipfs.object.get(out[0].hash), 4000)) }) - it('with wrap-with-directory=true', (done) => { + it('with wrap-with-directory=true', function (done) { + this.timeout(20 * 1000) + ipfs.util.addFromURL('http://ipfs.io/ipfs/QmWjppACLcFLQ2qL38unKQvJBhXH3RUtcGLPk7zmrTwV61/969165.jpg?foo=bar#buzz', { wrapWithDirectory: true }, (err, result) => { diff --git a/test/utils/interface-common-factory.js b/test/utils/interface-common-factory.js new file mode 100644 index 000000000..dbbf3eb18 --- /dev/null +++ b/test/utils/interface-common-factory.js @@ -0,0 +1,49 @@ +/* eslint-env mocha */ +'use strict' + +const each = require('async/each') +const IPFSFactory = require('ipfsd-ctl') +const IPFSApi = require('../../src') + +function createFactory (options) { + options = options || {} + + options.factoryOptions = options.factoryOptions || {} + options.spawnOptions = options.spawnOptions || { initOptions: { bits: 1024 } } + + const ipfsFactory = IPFSFactory.create(options.factoryOptions) + + return function createCommon () { + const nodes = [] + let setup, teardown + + if (options.createSetup) { + setup = options.createSetup({ ipfsFactory, nodes }, options) + } else { + setup = (callback) => { + callback(null, { + spawnNode (cb) { + ipfsFactory.spawn(options.spawnOptions, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) + } + } + + if (options.createTeardown) { + teardown = options.createTeardown({ ipfsFactory, nodes }, options) + } else { + teardown = callback => each(nodes, (node, cb) => node.stop(cb), callback) + } + + return { setup, teardown } + } +} + +exports.create = createFactory