diff --git a/package.json b/package.json index 3747d22a78..279fde99e3 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "expose-loader": "~0.7.5", "form-data": "^2.3.2", "hat": "0.0.3", - "interface-ipfs-core": "~0.69.2", + "interface-ipfs-core": "~0.70.2", "ipfsd-ctl": "~0.37.3", "mocha": "^5.1.1", "ncp": "^2.0.0", diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js new file mode 100644 index 0000000000..7f761bdf7b --- /dev/null +++ b/test/core/interface.spec.js @@ -0,0 +1,155 @@ +/* eslint-env mocha */ +'use strict' + +const tests = require('interface-ipfs-core') +const CommonFactory = require('../utils/interface-common-factory') +const isNode = require('detect-node') + +describe('interface-ipfs-core tests', () => { + const defaultCommonFactory = CommonFactory.create() + + tests.bitswap(defaultCommonFactory, { skip: !isNode }) + + tests.block(defaultCommonFactory) + + tests.bootstrap(defaultCommonFactory) + + tests.config(defaultCommonFactory) + + tests.dag(defaultCommonFactory) + + tests.dht(defaultCommonFactory, { + skip: { reason: 'TODO: DHT is not implemented in js-ipfs yet!' } + }) + + tests.files(defaultCommonFactory, { + skip: [ + { + name: 'cp', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'mkdir', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'stat', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'rm', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'read', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'readReadableStream', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'readPullStream', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'write', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'mv', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'flush', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'ls', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + } + ] + }) + + tests.key(CommonFactory.create({ + spawnOptions: { + args: ['--pass ipfs-is-awesome-software'], + initOptions: { bits: 512 } + } + })) + + tests.ls(defaultCommonFactory) + + tests.miscellaneous(CommonFactory.create({ + // No need to stop, because the test suite does a 'stop' test. + createTeardown: () => cb => cb() + })) + + tests.object(defaultCommonFactory) + + tests.pin(defaultCommonFactory) + + tests.ping(defaultCommonFactory, { + skip: isNode ? null : { + reason: 'FIXME: ping implementation requires DHT' + } + }) + + tests.pubsub(CommonFactory.create({ + spawnOptions: { + args: ['--enable-pubsub-experiment'], + initOptions: { bits: 512 } + } + }), { + skip: isNode ? null : { + reason: 'FIXME: disabled because no swarm addresses' + } + }) + + tests.repo(defaultCommonFactory, { + skip: [ + // repo.gc + { + name: 'gc', + reason: 'TODO: repo.gc is not implemented in js-ipfs yet!' + } + ] + }) + + 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: 512 } } + + ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + } + } + }), { skip: !isNode }) + + tests.types(defaultCommonFactory, { skip: { reason: 'FIXME: currently failing' } }) + + tests.util(defaultCommonFactory, { skip: { reason: 'FIXME: currently failing' } }) +}) diff --git a/test/core/interface/bitswap.js b/test/core/interface/bitswap.js deleted file mode 100644 index b7927dd5dd..0000000000 --- a/test/core/interface/bitswap.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.bitswap(common) diff --git a/test/core/interface/block.js b/test/core/interface/block.js deleted file mode 100644 index 2e3da76f22..0000000000 --- a/test/core/interface/block.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.block(common) diff --git a/test/core/interface/bootstrap.js b/test/core/interface/bootstrap.js deleted file mode 100644 index 20c0e69bb7..0000000000 --- a/test/core/interface/bootstrap.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.bootstrap(common) diff --git a/test/core/interface/config.js b/test/core/interface/config.js deleted file mode 100644 index 31cb73262b..0000000000 --- a/test/core/interface/config.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.config(common) diff --git a/test/core/interface/dag.js b/test/core/interface/dag.js deleted file mode 100644 index cc1d0ebfd7..0000000000 --- a/test/core/interface/dag.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.dag(common) diff --git a/test/core/interface/dht.js b/test/core/interface/dht.js deleted file mode 100644 index 532f3f4829..0000000000 --- a/test/core/interface/dht.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -/* -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -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, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} -test.dht(common) -*/ diff --git a/test/core/interface/files.js b/test/core/interface/files.js deleted file mode 100644 index db70520d59..0000000000 --- a/test/core/interface/files.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const IPFSFactory = require('ipfsd-ctl') -const f = IPFSFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - f.spawn({ - initOptions: { - bits: 512 - } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.files(common) diff --git a/test/core/interface/generic.js b/test/core/interface/generic.js deleted file mode 100644 index b7db2f3972..0000000000 --- a/test/core/interface/generic.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -// const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - 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/core/interface/interface.spec.js b/test/core/interface/interface.spec.js deleted file mode 100644 index 6bc0cdbe67..0000000000 --- a/test/core/interface/interface.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const isNode = require('detect-node') - -describe('interface-ipfs-core tests', () => { - require('./block') - require('./bootstrap') - require('./config') - require('./files') - require('./generic') - require('./object') - require('./dag') - require('./stats') - require('./key') - if (isNode) { - require('./bitswap') - require('./swarm') - require('./ping') - require('./pubsub') - require('./dht') - } -}) diff --git a/test/core/interface/key.js b/test/core/interface/key.js deleted file mode 100644 index 384486a4a2..0000000000 --- a/test/core/interface/key.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) -const options = { - args: ['--pass ipfs-is-awesome-software'], - initOptions: { bits: 512 } -} -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn(options, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.key(common) diff --git a/test/core/interface/object.js b/test/core/interface/object.js deleted file mode 100644 index bc63af3bf8..0000000000 --- a/test/core/interface/object.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.object(common) diff --git a/test/core/interface/pin.js b/test/core/interface/pin.js deleted file mode 100644 index 604a5e2440..0000000000 --- a/test/core/interface/pin.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.pin(common) diff --git a/test/core/interface/ping.js b/test/core/interface/ping.js deleted file mode 100644 index cc0f85b9c1..0000000000 --- a/test/core/interface/ping.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.ping(common) diff --git a/test/core/interface/pubsub.js b/test/core/interface/pubsub.js deleted file mode 100644 index 7dd5163995..0000000000 --- a/test/core/interface/pubsub.js +++ /dev/null @@ -1,36 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 }, - args: ['--enable-pubsub-experiment'] - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.pubsub(common) diff --git a/test/core/interface/stats.js b/test/core/interface/stats.js deleted file mode 100644 index 3524c3b9c2..0000000000 --- a/test/core/interface/stats.js +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.stats(common) diff --git a/test/core/interface/swarm.js b/test/core/interface/swarm.js deleted file mode 100644 index 933efb2f9c..0000000000 --- a/test/core/interface/swarm.js +++ /dev/null @@ -1,47 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const IPFS = require('../../../src') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -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 - } - - df.spawn({ - repoPath, - config, - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.swarm(common) diff --git a/test/http-api/interface.js b/test/http-api/interface.js new file mode 100644 index 0000000000..1f2955377b --- /dev/null +++ b/test/http-api/interface.js @@ -0,0 +1,148 @@ +/* eslint-env mocha */ +'use strict' + +const tests = require('interface-ipfs-core') +const CommonFactory = require('../utils/interface-common-factory') + +describe('interface-ipfs-core over ipfs-api tests', () => { + const defaultCommonFactory = CommonFactory.create({ + factoryOptions: { exec: 'src/cli/bin.js' } + }) + + tests.bitswap(defaultCommonFactory) + + tests.block(defaultCommonFactory) + + tests.bootstrap(defaultCommonFactory) + + tests.config(defaultCommonFactory) + + tests.dag(defaultCommonFactory, { + skip: { reason: 'TODO: DAG HTTP endpoints not implemented in js-ipfs yet!' } + }) + + tests.dht(defaultCommonFactory, { + skip: { reason: 'TODO: DHT is not implemented in js-ipfs yet!' } + }) + + tests.files(defaultCommonFactory, { + skip: [ + { + name: 'cp', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'mkdir', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'stat', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'rm', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'read', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'readReadableStream', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'readPullStream', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'write', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'mv', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'flush', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + }, + { + name: 'ls', + reason: 'TODO: MFS is not implemented in js-ipfs yet!' + } + ] + }) + + tests.key(CommonFactory.create({ + spawnOptions: { + args: ['--pass ipfs-is-awesome-software'], + initOptions: { bits: 512 } + } + })) + + tests.miscellaneous(CommonFactory.create({ + // No need to stop, because the test suite does a 'stop' test. + createTeardown: () => cb => cb() + })) + + tests.object(defaultCommonFactory) + + tests.pin(defaultCommonFactory) + + tests.ping(defaultCommonFactory) + + tests.pubsub(CommonFactory.create({ + spawnOptions: { + args: ['--enable-pubsub-experiment'], + initOptions: { bits: 512 } + } + })) + + tests.repo(defaultCommonFactory, { + skip: [ + // repo.gc + { + name: 'gc', + reason: 'TODO: repo.gc is not implemented in js-ipfs yet!' + } + ] + }) + + 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: 512 } } + + ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + } + } + })) + + tests.types(defaultCommonFactory, { skip: { reason: 'FIXME: currently failing' } }) + + tests.util(defaultCommonFactory, { skip: { reason: 'FIXME: currently failing' } }) +}) diff --git a/test/http-api/interface/bitswap.js b/test/http-api/interface/bitswap.js deleted file mode 100644 index 231a41cfe2..0000000000 --- a/test/http-api/interface/bitswap.js +++ /dev/null @@ -1,31 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.bitswap(common) diff --git a/test/http-api/interface/block.js b/test/http-api/interface/block.js deleted file mode 100644 index ef9e63f370..0000000000 --- a/test/http-api/interface/block.js +++ /dev/null @@ -1,31 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.block(common) diff --git a/test/http-api/interface/bootstrap.js b/test/http-api/interface/bootstrap.js deleted file mode 100644 index a41e18907e..0000000000 --- a/test/http-api/interface/bootstrap.js +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.bootstrap(common) diff --git a/test/http-api/interface/config.js b/test/http-api/interface/config.js deleted file mode 100644 index 6ac89facbf..0000000000 --- a/test/http-api/interface/config.js +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.config(common) diff --git a/test/http-api/interface/files.js b/test/http-api/interface/files.js deleted file mode 100644 index 8a80d4c2c1..0000000000 --- a/test/http-api/interface/files.js +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.files(common) diff --git a/test/http-api/interface/index.js b/test/http-api/interface/index.js deleted file mode 100644 index 7239f09e3a..0000000000 --- a/test/http-api/interface/index.js +++ /dev/null @@ -1,10 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const fs = require('fs') -const path = require('path') - -describe('## interface-ipfs-core over ipfs-api', () => { - fs.readdirSync(path.join(__dirname)) - .forEach((file) => file !== 'index.js' && require(`./${file}`)) -}) diff --git a/test/http-api/interface/key.js b/test/http-api/interface/key.js deleted file mode 100644 index 5feb04e412..0000000000 --- a/test/http-api/interface/key.js +++ /dev/null @@ -1,36 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) -const options = { - args: ['--pass', 'ipfs-is-awesome-software'], - initOptions: { bits: 512 } -} - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn(options, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.key(common) diff --git a/test/http-api/interface/object.js b/test/http-api/interface/object.js deleted file mode 100644 index 756c0a23b3..0000000000 --- a/test/http-api/interface/object.js +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.object(common) diff --git a/test/http-api/interface/pubsub.js b/test/http-api/interface/pubsub.js deleted file mode 100644 index 19e9384246..0000000000 --- a/test/http-api/interface/pubsub.js +++ /dev/null @@ -1,34 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) - -const nodes = [] -const common = { - setup: function (callback) { - callback(null, { - spawnNode: (cb) => { - df.spawn({ - args: ['--enable-pubsub-experiment'], - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.pubsub(common) diff --git a/test/http-api/interface/swarm.js b/test/http-api/interface/swarm.js deleted file mode 100644 index 568a41a64f..0000000000 --- a/test/http-api/interface/swarm.js +++ /dev/null @@ -1,45 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const test = require('interface-ipfs-core') -const parallel = require('async/parallel') - -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) - -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 - } - - df.spawn({ - repoPath, - config, - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - if (err) { - return cb(err) - } - - nodes.push(_ipfsd) - cb(null, _ipfsd.api) - }) - } - }) - }, - teardown: function (callback) { - parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) - } -} - -test.swarm(common) diff --git a/test/utils/interface-common-factory.js b/test/utils/interface-common-factory.js new file mode 100644 index 0000000000..97ed69b939 --- /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 IPFS = require('../../src') + +function createFactory (options) { + options = options || {} + + options.factoryOptions = options.factoryOptions || { type: 'proc', exec: IPFS } + options.spawnOptions = options.spawnOptions || { initOptions: { bits: 512 } } + + 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, _ipfsd.api) + }) + } + }) + } + } + + 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