diff --git a/test/http-api/extra/block.js b/test/http-api/extra/block.js index d75712321d..642d626a68 100644 --- a/test/http-api/extra/block.js +++ b/test/http-api/extra/block.js @@ -8,13 +8,26 @@ chai.use(dirtyChai) const multihash = require('multihashes') const waterfall = require('async/waterfall') -const getCtl = require('./utils/get-ctl.js') -module.exports = (http) => { - let ctl = null - before(() => { - ctl = getCtl(http) +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('extra block', () => { + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) }) + + after((done) => ipfsd.stop(done)) + describe('.block', () => { describe('.put', () => { it('updates value', (done) => { @@ -25,7 +38,7 @@ module.exports = (http) => { } waterfall([ - (cb) => ctl.block.put(data, cb), + (cb) => ipfs.block.put(data, cb), (block, cb) => { expect(block.cid.multihash).to.eql( multihash.fromB58String(expectedResult.key) @@ -38,14 +51,14 @@ module.exports = (http) => { describe('.get', () => { it('returns error for request with invalid argument', (done) => { - ctl.block.get('invalid', (err, result) => { + ipfs.block.get('invalid', (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.block.get('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { + ipfs.block.get('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { expect(err).to.not.exist() expect(result.data.toString()) .to.equal('hello world\n') @@ -56,21 +69,21 @@ module.exports = (http) => { describe('.stat', () => { it('returns error for request without argument', (done) => { - ctl.block.stat(null, (err, result) => { + ipfs.block.stat(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.block.stat('invalid', (err, result) => { + ipfs.block.stat('invalid', (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.block.stat('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { + ipfs.block.stat('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { expect(err).to.not.exist() expect(result.key) .to.equal('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') @@ -80,4 +93,4 @@ module.exports = (http) => { }) }) }) -} +}) diff --git a/test/http-api/extra/bootstrap.js b/test/http-api/extra/bootstrap.js index a0ab204cf4..b14075393c 100644 --- a/test/http-api/extra/bootstrap.js +++ b/test/http-api/extra/bootstrap.js @@ -1,3 +1,4 @@ +/* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ 'use strict' @@ -5,13 +6,26 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const getCtl = require('./utils/get-ctl.js') -module.exports = (http) => { - let ctl = null - before(() => { - ctl = getCtl(http) +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('extra bootstrap', () => { + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) }) + + after((done) => ipfsd.stop(done)) + describe('.bootstrap', () => { const invalidArg = 'this/Is/So/Invalid/' const validIp4 = '/ip4/101.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' @@ -21,14 +35,14 @@ module.exports = (http) => { this.timeout(40 * 1000) it('returns an error when called with an invalid arg', (done) => { - ctl.bootstrap.add(invalidArg, (err) => { + ipfs.bootstrap.add(invalidArg, (err) => { expect(err).to.be.an.instanceof(Error) done() }) }) it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => { - ctl.bootstrap.add(validIp4, (err, res) => { + ipfs.bootstrap.add(validIp4, (err, res) => { expect(err).to.not.exist() expect(res).to.be.eql({ Peers: [validIp4] }) done() @@ -36,20 +50,20 @@ module.exports = (http) => { }) it('prevents duplicate inserts of bootstrap peers', () => { - return ctl + return ipfs .bootstrap .rm(null, { all: true }) .then((res) => { expect(res.Peers.length).to.equal(0) - return ctl.bootstrap.add(validIp4) + return ipfs.bootstrap.add(validIp4) }) .then(res => { expect(res).to.be.eql({ Peers: [validIp4] }) - return ctl.bootstrap.add(validIp4) + return ipfs.bootstrap.add(validIp4) }) .then((res) => { expect(res).to.be.eql({ Peers: [validIp4] }) - return ctl.bootstrap.list() + return ipfs.bootstrap.list() }) .then((res) => { expect(res).to.exist() @@ -60,7 +74,7 @@ module.exports = (http) => { }) it('returns a list of bootstrap peers when called with the default option', (done) => { - ctl.bootstrap.add({ default: true }, (err, res) => { + ipfs.bootstrap.add({ default: true }, (err, res) => { expect(err).to.not.exist() peers = res.Peers expect(peers).to.exist() @@ -72,7 +86,7 @@ module.exports = (http) => { describe('.list', () => { it('returns a list of peers', (done) => { - ctl.bootstrap.list((err, res) => { + ipfs.bootstrap.list((err, res) => { expect(err).to.not.exist() peers = res.Peers expect(peers).to.exist() @@ -83,14 +97,14 @@ module.exports = (http) => { describe('.rm', () => { it('returns an error when called with an invalid arg', (done) => { - ctl.bootstrap.rm(invalidArg, (err) => { + ipfs.bootstrap.rm(invalidArg, (err) => { expect(err).to.be.an.instanceof(Error) done() }) }) it('returns empty list because no peers removed when called without an arg or options', (done) => { - ctl.bootstrap.rm(null, (err, res) => { + ipfs.bootstrap.rm(null, (err, res) => { expect(err).to.not.exist() peers = res.Peers expect(peers).to.exist() @@ -100,7 +114,7 @@ module.exports = (http) => { }) it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => { - ctl.bootstrap.rm(validIp4, (err, res) => { + ipfs.bootstrap.rm(validIp4, (err, res) => { expect(err).to.not.exist() peers = res.Peers @@ -111,7 +125,7 @@ module.exports = (http) => { }) it('returns list of all peers removed when all option is passed', (done) => { - ctl.bootstrap.rm(null, { all: true }, (err, res) => { + ipfs.bootstrap.rm(null, { all: true }, (err, res) => { expect(err).to.not.exist() peers = res.Peers expect(peers).to.exist() @@ -120,4 +134,4 @@ module.exports = (http) => { }) }) }) -} +}) diff --git a/test/http-api/extra/config.js b/test/http-api/extra/config.js index 6f4dcc868f..0d9ae6e907 100644 --- a/test/http-api/extra/config.js +++ b/test/http-api/extra/config.js @@ -6,33 +6,72 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const ncp = require('ncp').ncp +const rimraf = require('rimraf') +const waterfall = require('async/waterfall') + const fs = require('fs') const path = require('path') -const getCtl = require('./utils/get-ctl.js') -module.exports = (http) => { - let ctl = null - before(() => { - ctl = getCtl(http) - }) - describe('.config', () => { - const configPath = path.join(__dirname, '../../repo-tests-run/config') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('extra config', () => { + const repoExample = path.join(__dirname, '../../fixtures/go-ipfs-repo') + const repoTests = path.join(__dirname, '../../repo-tests-run') + + let updatedConfig = null + + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + + ncp(repoExample, repoTests, (err) => { + expect(err).to.not.exist() + + waterfall([ + (cb) => df.spawn({ + repoPath: repoTests, + initOptions: { bits: 512 }, + disposable: false, + start: true + }, cb), + (_ipfsd, cb) => { + ipfsd = _ipfsd + ipfsd.start(cb) + } + ], (err) => { + expect(err).to.not.exist() + ipfs = ipfsd.api + + updatedConfig = () => { + const file = fs.readFileSync(path.join(__dirname, '../../repo-tests-run/config')) + return JSON.parse(file, 'utf8') + } - let updatedConfig + done() + }) + }) + }) - before(() => { - updatedConfig = () => JSON.parse(fs.readFileSync(configPath, 'utf8')) + after((done) => { + rimraf(repoTests, (err) => { + expect(err).to.not.exist() + ipfsd.stop(done) }) + }) + describe('.config', () => { it('.get returns error for request with invalid argument', (done) => { - ctl.config.get('kittens', (err, res) => { + ipfs.config.get('kittens', (err, res) => { expect(err).to.exist() done() }) }) it('.get returns value for request with argument', (done) => { - ctl.config.get('API.HTTPHeaders', (err, value) => { + ipfs.config.get('API.HTTPHeaders', (err, value) => { expect(err).not.to.exist() expect(value).to.equal(null) done() @@ -40,35 +79,35 @@ module.exports = (http) => { }) it('.set updates value for request with both args', (done) => { - ctl.config.set('Datastore.Path', 'kitten', (err) => { + ipfs.config.set('Datastore.Path', 'kitten', (err) => { expect(err).not.to.exist() done() }) }) it('.set returns error for request with both args and JSON flag with invalid JSON argument', (done) => { - ctl.config.set('Datastore.Path', 'kitten', { json: true }, (err) => { + ipfs.config.set('Datastore.Path', 'kitten', { json: true }, (err) => { expect(err).to.exist() done() }) }) it('.set updates value for request with both args and bool flag and true argument', (done) => { - ctl.config.set('Datastore.Path', true, (err) => { + ipfs.config.set('Datastore.Path', true, (err) => { expect(err).not.to.exist() done() }) }) it('.set updates value for request with both args and bool flag and false argument', (done) => { - ctl.config.set('Datastore.Path', false, (err) => { + ipfs.config.set('Datastore.Path', false, (err) => { expect(err).not.to.exist() done() }) }) it('.get updatedConfig', (done) => { - ctl.config.get((err, config) => { + ipfs.config.get((err, config) => { expect(err).not.to.exist() expect(config).to.be.eql(updatedConfig()) done() @@ -81,7 +120,7 @@ module.exports = (http) => { it('returns error if the config is invalid', (done) => { const filePath = 'test/fixtures/test-data/badconfig' - ctl.config.replace(filePath, (err) => { + ipfs.config.replace(filePath, (err) => { expect(err).to.exist() done() }) @@ -91,7 +130,7 @@ module.exports = (http) => { const filePath = 'test/fixtures/test-data/otherconfig' const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8')) - ctl.config.replace(filePath, (err) => { + ipfs.config.replace(filePath, (err) => { expect(err).not.to.exist() expect(expectedConfig).to.deep.equal(updatedConfig()) done() @@ -99,4 +138,4 @@ module.exports = (http) => { }) }) }) -} +}) diff --git a/test/http-api/extra/dns.js b/test/http-api/extra/dns.js index f787d4cbf8..365dca73a2 100644 --- a/test/http-api/extra/dns.js +++ b/test/http-api/extra/dns.js @@ -5,20 +5,32 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const getCtl = require('./utils/get-ctl.js') -module.exports = (http) => { - let ctl = null - before(() => { - ctl = getCtl(http) +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('extra dns', () => { + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) }) + + after((done) => ipfsd.stop(done)) + describe('.dns', () => { it('resolve ipfs.io dns', (done) => { - ctl.dns('ipfs.io', (err, result) => { + ipfs.dns('ipfs.io', (err, result) => { expect(err).to.not.exist() expect(result).to.exist() done() }) }) }) -} +}) diff --git a/test/http-api/extra/id.js b/test/http-api/extra/id.js index d0635da7a9..3ee69bc4a1 100644 --- a/test/http-api/extra/id.js +++ b/test/http-api/extra/id.js @@ -5,16 +5,56 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const getCtl = require('./utils/get-ctl.js') -module.exports = (http) => { - let ctl = null - before(() => { - ctl = getCtl(http) +const ncp = require('ncp').ncp +const rimraf = require('rimraf') +const waterfall = require('async/waterfall') +const path = require('path') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('extra id', () => { + const repoExample = path.join(__dirname, '../../fixtures/go-ipfs-repo') + const repoTests = path.join(__dirname, '../../repo-tests-run') + + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + + ncp(repoExample, repoTests, (err) => { + expect(err).to.not.exist() + + waterfall([ + (cb) => df.spawn({ + repoPath: path.join(__dirname, '../../fixtures/go-ipfs-repo'), + initOptions: { bits: 512 }, + disposable: false, + start: true + }, cb), + (_ipfsd, cb) => { + ipfsd = _ipfsd + ipfsd.start(cb) + } + ], (err) => { + expect(err).to.not.exist() + ipfs = ipfsd.api + done() + }) + }) }) + + after((done) => { + rimraf(repoTests, (err) => { + expect(err).to.not.exist() + ipfsd.stop(done) + }) + }) + describe('.id', () => { it('get the identity', (done) => { - ctl.id((err, result) => { + ipfs.id((err, result) => { expect(err).to.not.exist() expect(result.id).to.equal(idResult.ID) expect(result.publicKey).to.equal(idResult.PublicKey) @@ -26,12 +66,12 @@ module.exports = (http) => { }) }) }) -} +}) const idResult = { ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A', PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=', - Addresses: [ '/ip4/0.0.0.0/tcp/0' ], + Addresses: ['/ip4/0.0.0.0/tcp/0'], AgentVersion: 'js-ipfs', ProtocolVersion: '9000' } diff --git a/test/http-api/extra/index.js b/test/http-api/extra/index.js new file mode 100644 index 0000000000..fff181e750 --- /dev/null +++ b/test/http-api/extra/index.js @@ -0,0 +1,16 @@ +/* eslint-env mocha */ +'use strict' + +const fs = require('fs') +const path = require('path') + +describe('## extra tests with ipfs-api', () => { + fs.readdirSync(path.join(__dirname)) + .forEach((file) => { + // TODO(victor) want to make all this loading of tests proper, but for now + if (file.includes('utils') || file.includes('index.js')) { + return + } + require(`./${file}`) + }) +}) diff --git a/test/http-api/extra/object.js b/test/http-api/extra/object.js index d24a836867..eced7f28f6 100644 --- a/test/http-api/extra/object.js +++ b/test/http-api/extra/object.js @@ -10,7 +10,9 @@ chai.use(dirtyChai) const fs = require('fs') const dagPB = require('ipld-dag-pb') const DAGLink = dagPB.DAGLink -const getCtl = require('./utils/get-ctl.js') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) function asJson (cb) { return (err, result) => { @@ -20,14 +22,25 @@ function asJson (cb) { } } -module.exports = (http) => { - let ctl = null - before(() => { - ctl = getCtl(http) +describe('extra object', () => { + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) }) + + after((done) => ipfsd.stop(done)) + describe('.object', () => { it('.new', (done) => { - ctl.object.new(asJson((err, res) => { + ipfs.object.new(asJson((err, res) => { expect(err).to.not.exist() expect(res.multihash) .to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n') @@ -38,21 +51,21 @@ module.exports = (http) => { describe('.get', () => { it('returns error for request without argument', (done) => { - ctl.object.get(null, (err, result) => { + ipfs.object.get(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.object.get('invalid', {enc: 'base58'}, (err, result) => { + ipfs.object.get('invalid', { enc: 'base58' }, (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.object.get('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', {enc: 'base58'}, asJson((err, res) => { + ipfs.object.get('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', { enc: 'base58' }, asJson((err, res) => { expect(err).to.not.exist() expect(res.links).to.be.eql([]) expect(res.data).to.eql(Buffer.from('')) @@ -65,7 +78,7 @@ module.exports = (http) => { it('returns error if the node is invalid', (done) => { const filePath = 'test/fixtures/test-data/badnode.json' - ctl.object.put(filePath, {enc: 'json'}, (err) => { + ipfs.object.put(filePath, { enc: 'json' }, (err) => { expect(err).to.exist() done() }) @@ -84,7 +97,7 @@ module.exports = (http) => { size: 68 } - ctl.object.put(filePath, {enc: 'json'}, asJson((err, res) => { + ipfs.object.put(filePath, { enc: 'json' }, asJson((err, res) => { expect(err).to.not.exist() expect(res).to.eql(expectedResult) done() @@ -94,21 +107,21 @@ module.exports = (http) => { describe('.stat', () => { it('returns error for request without argument', (done) => { - ctl.object.stat(null, (err, result) => { + ipfs.object.stat(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.object.stat('invalid', {enc: 'base58'}, (err, result) => { + ipfs.object.stat('invalid', { enc: 'base58' }, (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.object.stat('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', {enc: 'base58'}, (err, result) => { + ipfs.object.stat('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', { enc: 'base58' }, (err, result) => { expect(err).to.not.exist() expect(result.Hash).to.equal('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm') expect(result.NumLinks).to.equal(1) @@ -123,21 +136,21 @@ module.exports = (http) => { describe('.data', () => { it('returns error for request without argument', (done) => { - ctl.object.data(null, (err, result) => { + ipfs.object.data(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.object.data('invalid', {enc: 'base58'}, (err, result) => { + ipfs.object.data('invalid', { enc: 'base58' }, (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.object.data('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', {enc: 'base58'}, (err, result) => { + ipfs.object.data('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', { enc: 'base58' }, (err, result) => { expect(err).to.not.exist() expect(result.toString()).to.equal('another') done() @@ -147,14 +160,14 @@ module.exports = (http) => { describe('.links', () => { it('returns error for request without argument', (done) => { - ctl.object.links(null, (err, result) => { + ipfs.object.links(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.object.links('invalid', {enc: 'base58'}, (err, result) => { + ipfs.object.links('invalid', { enc: 'base58' }, (err, result) => { expect(err).to.exist() done() }) @@ -167,7 +180,7 @@ module.exports = (http) => { size: 8 } - ctl.object.links('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', {enc: 'base58'}, (err, result) => { + ipfs.object.links('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', { enc: 'base58' }, (err, result) => { expect(err).to.not.exist() expect(result[0].toJSON()).to.deep.equal(expectedResult) done() @@ -177,7 +190,7 @@ module.exports = (http) => { describe('.patch.appendData', () => { it('returns error for request without key & data', (done) => { - ctl.object.patch.appendData(null, null, (err) => { + ipfs.object.patch.appendData(null, null, (err) => { expect(err).to.exist() done() }) @@ -186,7 +199,7 @@ module.exports = (http) => { it('returns error for request without data', (done) => { const filePath = 'test/fixtures/test-data/badnode.json' - ctl.object.patch.appendData(null, filePath, (err) => { + ipfs.object.patch.appendData(null, filePath, (err) => { expect(err).to.exist() done() }) @@ -202,7 +215,7 @@ module.exports = (http) => { size: 19 } - ctl.object.patch.appendData(key, filePath, {enc: 'base58'}, asJson((err, res) => { + ipfs.object.patch.appendData(key, filePath, { enc: 'base58' }, asJson((err, res) => { expect(err).to.not.exist() expect(res).to.eql(expectedResult) done() @@ -212,7 +225,7 @@ module.exports = (http) => { describe('.patch.setData', () => { it('returns error for request without key & data', (done) => { - ctl.object.patch.setData(null, null, (err) => { + ipfs.object.patch.setData(null, null, (err) => { expect(err).to.exist() done() }) @@ -221,7 +234,7 @@ module.exports = (http) => { it('returns error for request without data', (done) => { const filePath = 'test/fixtures/test-data/badnode.json' - ctl.object.patch.setData(null, filePath, (err) => { + ipfs.object.patch.setData(null, filePath, (err) => { expect(err).to.exist() done() }) @@ -237,7 +250,7 @@ module.exports = (http) => { size: 19 } - ctl.object.patch.setData(key, filePath, {enc: 'base58'}, asJson((err, res) => { + ipfs.object.patch.setData(key, filePath, { enc: 'base58' }, asJson((err, res) => { expect(err).to.not.exist() expect(res).to.eql(expectedResult) done() @@ -247,14 +260,14 @@ module.exports = (http) => { describe('.patch.addLink', () => { it('returns error for request without arguments', (done) => { - ctl.object.patch.addLink(null, null, null, (err) => { + ipfs.object.patch.addLink(null, null, null, (err) => { expect(err).to.exist() done() }) }) it('returns error for request only one invalid argument', (done) => { - ctl.object.patch.addLink('invalid', null, null, (err) => { + ipfs.object.patch.addLink('invalid', null, null, (err) => { expect(err).to.exist() done() }) @@ -265,7 +278,7 @@ module.exports = (http) => { const name = '' const ref = 'QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM' const link = new DAGLink(name, 2, ref) - ctl.object.patch.addLink(root, link, {enc: 'base58'}, (err) => { + ipfs.object.patch.addLink(root, link, { enc: 'base58' }, (err) => { expect(err).to.exist() done() }) @@ -276,7 +289,7 @@ module.exports = (http) => { const name = 'foo' const ref = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' const link = new DAGLink(name, 10, ref) - ctl.object.patch.addLink(root, link, {enc: 'base58'}, asJson((err, res) => { + ipfs.object.patch.addLink(root, link, { enc: 'base58' }, asJson((err, res) => { expect(err).not.to.exist() expect(res.multihash).to.equal('QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK') expect(res.links[0]).to.eql({ @@ -291,14 +304,14 @@ module.exports = (http) => { describe('.patch.rmLink', () => { it('returns error for request without arguments', (done) => { - ctl.object.patch.rmLink(null, null, (err) => { + ipfs.object.patch.rmLink(null, null, (err) => { expect(err).to.exist() done() }) }) it('returns error for request only one invalid argument', (done) => { - ctl.object.patch.rmLink('invalid', null, (err) => { + ipfs.object.patch.rmLink('invalid', null, (err) => { expect(err).to.exist() done() }) @@ -308,11 +321,11 @@ module.exports = (http) => { const root = '' const link = 'foo' - ctl.object.patch.rmLink(root, link, (err) => { + ipfs.object.patch.rmLink(root, link, (err) => { expect(err).to.exist() done() }) }) }) }) -} +}) diff --git a/test/http-api/extra/version.js b/test/http-api/extra/version.js index 2adb18ecd9..8a22deff0d 100644 --- a/test/http-api/extra/version.js +++ b/test/http-api/extra/version.js @@ -5,16 +5,28 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const getCtl = require('./utils/get-ctl.js') -module.exports = (http) => { - let ctl = null - before(() => { - ctl = getCtl(http) +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('extra version', () => { + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) }) + + after((done) => ipfsd.stop(done)) + describe('.version', () => { it('get the version', (done) => { - ctl.version((err, result) => { + ipfs.version((err, result) => { expect(err).to.not.exist() expect(result).to.have.a.property('version') expect(result).to.have.a.property('commit') @@ -23,4 +35,4 @@ module.exports = (http) => { }) }) }) -} +}) diff --git a/test/http-api/index.js b/test/http-api/index.js index 99c5a86adc..0d6941e9dd 100644 --- a/test/http-api/index.js +++ b/test/http-api/index.js @@ -1,79 +1,5 @@ -/* eslint-env mocha */ 'use strict' -const fs = require('fs') -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) -const hat = require('hat') -const API = require('../../src/http') -const ncp = require('ncp').ncp -const path = require('path') -const clean = require('../utils/clean') - -describe('HTTP API', () => { - const repoExample = path.join(__dirname, '../fixtures/go-ipfs-repo') - const repoTests = path.join(__dirname, '../repo-tests-run') - - let http = {} - - const startHttpAPI = (cb) => { - const options = { - pass: hat(), - enablePubsubExperiment: true - } - http.api = new API(repoTests, null, options) - - ncp(repoExample, repoTests, (err) => { - if (err) { - return cb(err) - } - - http.api.start(false, (err) => { - if (err) { - return cb(err) - } - cb(null, http) - }) - }) - } - - before(function (done) { - this.timeout(60 * 1000) - startHttpAPI((err, _http) => { - if (err) { - throw err - } - http = _http - done() - }) - }) - - after((done) => http.api.stop((err) => { - expect(err).to.not.exist() - clean(repoTests) - done() - })) - - describe('## http-api spec tests', () => { - fs.readdirSync(path.join(__dirname, '/spec')) - .forEach((file) => require('./spec/' + file)(http)) - }) - - describe('## interface-ipfs-core over ipfs-api', () => { - fs.readdirSync(path.join(__dirname, '/interface')) - .forEach((file) => require('./interface/' + file)) - }) - - describe('## extra tests with ipfs-api', () => { - fs.readdirSync(path.join(__dirname, '/extra')) - .forEach((file) => { - // TODO(victor) want to make all this loading of tests proper, but for now - if (file.includes('utils')) { - return - } - require('./extra/' + file)(http) - }) - }) -}) +require('./spec') +require('./interface') +require('./extra') diff --git a/test/http-api/interface/block.js b/test/http-api/interface/block.js index a3a7717f03..ef9e63f370 100644 --- a/test/http-api/interface/block.js +++ b/test/http-api/interface/block.js @@ -12,9 +12,7 @@ const common = { setup: function (callback) { callback(null, { spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { if (err) { return cb(err) } diff --git a/test/http-api/interface/index.js b/test/http-api/interface/index.js new file mode 100644 index 0000000000..7239f09e3a --- /dev/null +++ b/test/http-api/interface/index.js @@ -0,0 +1,10 @@ +/* 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/spec/index.js b/test/http-api/spec/index.js new file mode 100644 index 0000000000..24d94ebc4e --- /dev/null +++ b/test/http-api/spec/index.js @@ -0,0 +1,63 @@ +/* eslint-env mocha */ +'use strict' + +const fs = require('fs') +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) +const hat = require('hat') +const API = require('../../../src/http/index') +const ncp = require('ncp').ncp +const path = require('path') +const clean = require('../../utils/clean') + +describe('HTTP API', () => { + const repoExample = path.join(__dirname, '../../fixtures/go-ipfs-repo') + const repoTests = path.join(__dirname, '../../repo-tests-run') + + let http = {} + + const startHttpAPI = (cb) => { + const options = { + pass: hat(), + enablePubsubExperiment: true + } + http.api = new API(repoTests, null, options) + + ncp(repoExample, repoTests, (err) => { + if (err) { + return cb(err) + } + + http.api.start(false, (err) => { + if (err) { + return cb(err) + } + cb(null, http) + }) + }) + } + + before(function (done) { + this.timeout(60 * 1000) + startHttpAPI((err, _http) => { + if (err) { + throw err + } + http = _http + done() + }) + }) + + after((done) => http.api.stop((err) => { + expect(err).to.not.exist() + clean(repoTests) + done() + })) + + describe('## http-api spec tests', () => { + fs.readdirSync(path.join(__dirname)) + .forEach((file) => file !== 'index.js' && require(`./${file}`)(http)) + }) +})