From 210dabb3a857bd6e832f37c64b90ad0fcdba6519 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Fri, 12 Jan 2018 15:33:31 +0000 Subject: [PATCH 1/8] chore: update dependency: pump version 2.0 (#668) --- package.json | 2 +- src/log/tail.js | 3 ++- src/utils/converter.js | 5 +++-- src/utils/send-request.js | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2ade22be6..ab520573a 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "promisify-es6": "^1.0.3", "pull-defer": "^0.2.2", "pull-pushable": "^2.1.2", - "pump": "^1.0.3", + "pump": "^2.0.0", "qs": "^6.5.1", "readable-stream": "^2.3.3", "stream-http": "^2.7.2", diff --git a/src/log/tail.js b/src/log/tail.js index d5be9713f..bad4e4d34 100644 --- a/src/log/tail.js +++ b/src/log/tail.js @@ -12,7 +12,8 @@ module.exports = (send) => { if (err) { return callback(err) } - const outputStream = pump(response, ndjson.parse()) + const outputStream = ndjson.parse() + pump(response, outputStream) callback(null, outputStream) }) }) diff --git a/src/utils/converter.js b/src/utils/converter.js index 444064bf3..b721173e1 100644 --- a/src/utils/converter.js +++ b/src/utils/converter.js @@ -44,9 +44,10 @@ class ConverterStream extends TransformStream { } function converter (inputStream, callback) { - const outputStream = pump( + const outputStream = new ConverterStream() + pump( inputStream, - new ConverterStream(), + outputStream, (err) => { if (err) { callback(err) diff --git a/src/utils/send-request.js b/src/utils/send-request.js index 3ab2b57e9..90f436d47 100644 --- a/src/utils/send-request.js +++ b/src/utils/send-request.js @@ -46,7 +46,8 @@ function onRes (buffer, cb) { // Return a stream of JSON objects if (chunkedObjects && isJson) { - const outputStream = pump(res, ndjson.parse()) + const outputStream = ndjson.parse() + pump(res, outputStream) res.on('end', () => { let err = res.trailers['x-stream-error'] if (err) { From 5803d39b6b5c7b9621c537f63cc46af696cd986d Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 18 Jan 2018 23:14:30 +0000 Subject: [PATCH 2/8] fix: normalize stats fields (#669) --- src/stats/bitswap.js | 18 ++++++- src/stats/bw.js | 25 ++++++---- src/stats/repo.js | 14 +++++- test/fixtures/test-folder/hello-link | 0 test/stats.spec.js | 72 ++++++++++++++-------------- 5 files changed, 80 insertions(+), 49 deletions(-) mode change 120000 => 100644 test/fixtures/test-folder/hello-link diff --git a/src/stats/bitswap.js b/src/stats/bitswap.js index 619bd0809..9c893fa1c 100644 --- a/src/stats/bitswap.js +++ b/src/stats/bitswap.js @@ -2,6 +2,20 @@ const promisify = require('promisify-es6') +const transform = function (res, callback) { + callback(null, { + provideBufLen: res.ProvideBufLen, + wantlist: res.Wantlist, + peers: res.Peers, + blocksReceived: res.BlocksReceived, + dataReceived: res.DataReceived, + blocksSent: res.BlocksSent, + dataSent: res.DataSent, + dupBlksReceived: res.DupBlksReceived, + dupDataReceived: res.DupDataReceived + }) +} + module.exports = (send) => { return promisify((opts, callback) => { if (typeof (opts) === 'function') { @@ -9,9 +23,9 @@ module.exports = (send) => { opts = {} } - send({ + send.andTransform({ path: 'stats/bitswap', qs: opts - }, callback) + }, transform, callback) }) } diff --git a/src/stats/bw.js b/src/stats/bw.js index a7ee05677..3c0d79c87 100644 --- a/src/stats/bw.js +++ b/src/stats/bw.js @@ -3,6 +3,21 @@ const promisify = require('promisify-es6') const streamToValue = require('../utils/stream-to-value') +const transform = function (res, callback) { + streamToValue(res, (err, data) => { + if (err) { + return callback(err) + } + + callback(null, { + totalIn: data[0].TotalIn, + totalOut: data[0].TotalOut, + rateIn: data[0].RateIn, + rateOut: data[0].RateOut + }) + }) +} + module.exports = (send) => { return promisify((opts, callback) => { if (typeof (opts) === 'function') { @@ -13,14 +28,6 @@ module.exports = (send) => { send.andTransform({ path: 'stats/bw', qs: opts - }, streamToValue, (err, stats) => { - if (err) { - return callback(err) - } - - // streamToValue returns an array and we're only - // interested in returning the object itself. - callback(err, stats[0]) - }) + }, transform, callback) }) } diff --git a/src/stats/repo.js b/src/stats/repo.js index 71a180363..55a8fdd68 100644 --- a/src/stats/repo.js +++ b/src/stats/repo.js @@ -3,6 +3,16 @@ const promisify = require('promisify-es6') +const transform = function (res, callback) { + callback(null, { + numObjects: res.NumObjects, + repoSize: res.RepoSize, + repoPath: res.RepoPath, + version: res.Version, + storageMax: res.StorageMax + }) +} + module.exports = (send) => { return promisify((opts, callback) => { if (typeof (opts) === 'function') { @@ -10,9 +20,9 @@ module.exports = (send) => { opts = {} } - send({ + send.andTransform({ path: 'stats/repo', qs: opts - }, callback) + }, transform, callback) }) } diff --git a/test/fixtures/test-folder/hello-link b/test/fixtures/test-folder/hello-link deleted file mode 120000 index 50b07e9e7..000000000 --- a/test/fixtures/test-folder/hello-link +++ /dev/null @@ -1 +0,0 @@ -files/hello.txt \ No newline at end of file diff --git a/test/fixtures/test-folder/hello-link b/test/fixtures/test-folder/hello-link new file mode 100644 index 000000000..50b07e9e7 --- /dev/null +++ b/test/fixtures/test-folder/hello-link @@ -0,0 +1 @@ +files/hello.txt \ No newline at end of file diff --git a/test/stats.spec.js b/test/stats.spec.js index 24d54731a..8775d88ed 100644 --- a/test/stats.spec.js +++ b/test/stats.spec.js @@ -31,15 +31,15 @@ describe('stats', function () { ipfs.stats.bitswap((err, res) => { expect(err).to.not.exist() expect(res).to.exist() - expect(res).to.have.a.property('ProvideBufLen') - expect(res).to.have.a.property('Wantlist') - expect(res).to.have.a.property('Peers') - expect(res).to.have.a.property('BlocksReceived') - expect(res).to.have.a.property('DataReceived') - expect(res).to.have.a.property('BlocksSent') - expect(res).to.have.a.property('DataSent') - expect(res).to.have.a.property('DupBlksReceived') - expect(res).to.have.a.property('DupDataReceived') + expect(res).to.have.a.property('provideBufLen') + expect(res).to.have.a.property('wantlist') + expect(res).to.have.a.property('peers') + expect(res).to.have.a.property('blocksReceived') + expect(res).to.have.a.property('dataReceived') + expect(res).to.have.a.property('blocksSent') + expect(res).to.have.a.property('dataSent') + expect(res).to.have.a.property('dupBlksReceived') + expect(res).to.have.a.property('dupDataReceived') done() }) }) @@ -48,10 +48,10 @@ describe('stats', function () { ipfs.stats.bw((err, res) => { expect(err).to.not.exist() expect(res).to.exist() - expect(res).to.have.a.property('TotalIn') - expect(res).to.have.a.property('TotalOut') - expect(res).to.have.a.property('RateIn') - expect(res).to.have.a.property('RateOut') + expect(res).to.have.a.property('totalIn') + expect(res).to.have.a.property('totalOut') + expect(res).to.have.a.property('rateIn') + expect(res).to.have.a.property('rateOut') done() }) }) @@ -60,11 +60,11 @@ describe('stats', function () { ipfs.stats.repo((err, res) => { expect(err).to.not.exist() expect(res).to.exist() - expect(res).to.have.a.property('NumObjects') - expect(res).to.have.a.property('RepoSize') - expect(res).to.have.a.property('RepoPath') - expect(res).to.have.a.property('Version') - expect(res).to.have.a.property('StorageMax') + expect(res).to.have.a.property('numObjects') + expect(res).to.have.a.property('repoSize') + expect(res).to.have.a.property('repoPath') + expect(res).to.have.a.property('version') + expect(res).to.have.a.property('storageMax') done() }) }) @@ -75,10 +75,10 @@ describe('stats', function () { return ipfs.stats.bw() .then((res) => { expect(res).to.exist() - expect(res).to.have.a.property('TotalIn') - expect(res).to.have.a.property('TotalOut') - expect(res).to.have.a.property('RateIn') - expect(res).to.have.a.property('RateOut') + expect(res).to.have.a.property('totalIn') + expect(res).to.have.a.property('totalOut') + expect(res).to.have.a.property('rateIn') + expect(res).to.have.a.property('rateOut') }) }) @@ -86,11 +86,11 @@ describe('stats', function () { return ipfs.stats.repo() .then((res) => { expect(res).to.exist() - expect(res).to.have.a.property('NumObjects') - expect(res).to.have.a.property('RepoSize') - expect(res).to.have.a.property('RepoPath') - expect(res).to.have.a.property('Version') - expect(res).to.have.a.property('StorageMax') + expect(res).to.have.a.property('numObjects') + expect(res).to.have.a.property('repoSize') + expect(res).to.have.a.property('repoPath') + expect(res).to.have.a.property('version') + expect(res).to.have.a.property('storageMax') }) }) @@ -98,15 +98,15 @@ describe('stats', function () { return ipfs.stats.bitswap() .then((res) => { expect(res).to.exist() - expect(res).to.have.a.property('ProvideBufLen') - expect(res).to.have.a.property('Wantlist') - expect(res).to.have.a.property('Peers') - expect(res).to.have.a.property('BlocksReceived') - expect(res).to.have.a.property('DataReceived') - expect(res).to.have.a.property('BlocksSent') - expect(res).to.have.a.property('DataSent') - expect(res).to.have.a.property('DupBlksReceived') - expect(res).to.have.a.property('DupDataReceived') + expect(res).to.have.a.property('provideBufLen') + expect(res).to.have.a.property('wantlist') + expect(res).to.have.a.property('peers') + expect(res).to.have.a.property('blocksReceived') + expect(res).to.have.a.property('dataReceived') + expect(res).to.have.a.property('blocksSent') + expect(res).to.have.a.property('dataSent') + expect(res).to.have.a.property('dupBlksReceived') + expect(res).to.have.a.property('dupDataReceived') }) }) }) From 98000af3fe9c15aa7f6a594f760bff2f3d373095 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 21 Jan 2018 00:14:27 +0000 Subject: [PATCH 3/8] feat (breaking change): normalize fields on files.ls and flatten output (#670) --- src/files/ls.js | 15 +++++++++++++-- src/files/stat.js | 14 ++++++++++++-- test/files.spec.js | 24 ++++++++++++------------ 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/files/ls.js b/src/files/ls.js index e87f07719..fe6ee275e 100644 --- a/src/files/ls.js +++ b/src/files/ls.js @@ -2,16 +2,27 @@ const promisify = require('promisify-es6') +const transform = function (res, callback) { + callback(null, res.Entries.map((entry) => { + return { + name: entry.Name, + type: entry.Type, + size: entry.Size, + hash: entry.Hash + } + })) +} + module.exports = (send) => { return promisify((args, opts, callback) => { if (typeof (opts) === 'function') { callback = opts opts = {} } - return send({ + return send.andTransform({ path: 'files/ls', args: args, qs: opts - }, callback) + }, transform, callback) }) } diff --git a/src/files/stat.js b/src/files/stat.js index 845901b98..d53da0dab 100644 --- a/src/files/stat.js +++ b/src/files/stat.js @@ -2,16 +2,26 @@ const promisify = require('promisify-es6') +const transform = function (res, callback) { + callback(null, { + type: res.Type, + blocks: res.Blocks, + size: res.Size, + hash: res.Hash, + cumulativeSize: res.CumulativeSize + }) +} + module.exports = (send) => { return promisify((args, opts, callback) => { if (typeof (opts) === 'function') { callback = opts opts = {} } - send({ + send.andTransform({ path: 'files/stat', args: args, qs: opts - }, callback) + }, transform, callback) }) } diff --git a/test/files.spec.js b/test/files.spec.js index 6806643eb..c1ccc56d1 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -231,7 +231,7 @@ describe('.files (the MFS API part)', function () { it('files.ls', (done) => { ipfs.files.ls('/test-folder', (err, res) => { expect(err).to.not.exist() - expect(res.Entries.length).to.equal(1) + expect(res.length).to.equal(1) done() }) }) @@ -286,11 +286,11 @@ describe('.files (the MFS API part)', function () { ipfs.files.stat('/test-folder/test-file', (err, res) => { expect(err).to.not.exist() expect(res).to.deep.equal({ - Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - Size: 12, - CumulativeSize: 20, - Blocks: 0, - Type: 'file' + hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + size: 12, + cumulativeSize: 20, + blocks: 0, + type: 'file' }) done() @@ -404,7 +404,7 @@ describe('.files (the MFS API part)', function () { it('files.ls', () => { return ipfs.files.ls('/test-folder') .then((res) => { - expect(res.Entries.length).to.equal(1) + expect(res.length).to.equal(1) }) }) @@ -458,11 +458,11 @@ describe('.files (the MFS API part)', function () { return ipfs.files.stat('/test-folder/test-file') .then((res) => { expect(res).to.deep.equal({ - Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - Size: 12, - CumulativeSize: 20, - Blocks: 0, - Type: 'file' + hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + size: 12, + cumulativeSize: 20, + blocks: 0, + type: 'file' }) }) }) From 2b1820b74e229d39e4c479e307244acf4139543d Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 23 Jan 2018 14:17:13 -0800 Subject: [PATCH 4/8] feat: integrate new ipfsd-ctl --- .aegir.js | 11 ++- package.json | 10 ++- test/bitswap.spec.js | 92 +++++++------------ test/bootstrap.spec.js | 18 ++-- test/commands.spec.js | 17 ++-- test/constructor.spec.js | 14 +-- test/diag.spec.js | 16 ++-- test/files.spec.js | 15 ++-- test/fixtures/test-folder/hello-link | 0 test/get.spec.js | 25 ++++-- test/interface/block.spec.js | 24 +++-- test/interface/config.spec.js | 24 +++-- test/interface/dht.spec.js | 24 +++-- test/interface/files.spec.js | 23 +++-- test/interface/generic.spec.js | 24 +++-- test/interface/key.spec.js | 24 +++-- test/interface/object.spec.js | 24 +++-- test/interface/pin.spec.js | 24 +++-- test/interface/pubsub.spec.js | 28 ++++-- test/interface/swarm.spec.js | 34 +++++-- test/ipfs-factory/client.js | 60 ------------- test/ipfs-factory/daemon-spawner.js | 90 ------------------- test/ipfs-factory/server-routes.js | 35 -------- test/ipfs-factory/server.js | 28 ------ test/ipfs-factory/tasks.js | 22 ----- test/key.spec.js | 22 ++--- test/log.spec.js | 16 ++-- test/name.spec.js | 37 +++++--- test/ping.spec.js | 32 ++++--- test/pubsub-in-browser.spec.js | 61 +++++-------- test/refs.spec.js | 24 +++-- test/repo.spec.js | 18 ++-- test/stats.spec.js | 129 +++++++++------------------ test/util.spec.js | 16 ++-- 34 files changed, 479 insertions(+), 582 deletions(-) mode change 100644 => 120000 test/fixtures/test-folder/hello-link delete mode 100644 test/ipfs-factory/client.js delete mode 100644 test/ipfs-factory/daemon-spawner.js delete mode 100644 test/ipfs-factory/server-routes.js delete mode 100644 test/ipfs-factory/server.js delete mode 100644 test/ipfs-factory/tasks.js diff --git a/.aegir.js b/.aegir.js index 0e7eebbde..7f287dd89 100644 --- a/.aegir.js +++ b/.aegir.js @@ -1,7 +1,8 @@ 'use strict' -const factory = require('./test/ipfs-factory/tasks') +const createServer = require('ipfsd-ctl').createServer +const server = createServer() module.exports = { karma: { files: [{ @@ -9,10 +10,12 @@ module.exports = { watched: false, served: true, included: false - }] + }], + browserNoActivityTimeout: 100 * 1000, + singleRun: true }, hooks: { - pre: factory.start, - post: factory.stop + pre: server.start.bind(server), + post: server.stop.bind(server) } } diff --git a/package.json b/package.json index ab520573a..58ab6abdd 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,10 @@ "http": "stream-http" }, "scripts": { - "test": "aegir test ", - "test:node": "aegir test -t node ", + "test": "aegir test", + "test:node": "aegir test -t node", "test:browser": "aegir test -t browser", + "test:webworker": "aegir test -t webworker", "lint": "aegir lint", "build": "aegir build", "release": "aegir release ", @@ -65,10 +66,11 @@ "chai": "^4.1.2", "dirty-chai": "^2.0.1", "eslint-plugin-react": "^7.5.1", + "go-ipfs-dep": "^0.4.13", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.40.0", + "interface-ipfs-core": "~0.41.0", "hapi": "^16.6.2", - "ipfsd-ctl": "~0.26.0", + "ipfsd-ctl": "~0.27.0", "pre-commit": "^1.2.2", "socket.io": "^2.0.4", "socket.io-client": "^2.0.4", diff --git a/test/bitswap.spec.js b/test/bitswap.spec.js index 35cd7a855..46051e258 100644 --- a/test/bitswap.spec.js +++ b/test/bitswap.spec.js @@ -5,86 +5,58 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.bitswap', function () { this.timeout(20 * 1000) // slow CI let ipfs - let fc + let ipfsd = null before((done) => { this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - fc.dismantle(done) - }) - - describe('Callback API', () => { - it('.wantlist', (done) => { - ipfs.bitswap.wantlist((err, res) => { - expect(err).to.not.exist() - expect(res).to.have.to.be.eql({ - Keys: null - }) - done() - }) - }) - - it('.stat', (done) => { - ipfs.bitswap.stat((err, res) => { - expect(err).to.not.exist() - expect(res).to.have.property('BlocksReceived') - expect(res).to.have.property('DupBlksReceived') - expect(res).to.have.property('DupDataReceived') - expect(res).to.have.property('Peers') - expect(res).to.have.property('ProvideBufLen') - expect(res).to.have.property('Wantlist') - - done() - }) - }) + after((done) => ipfsd.stop(done)) - it('.unwant', (done) => { - const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - ipfs.bitswap.unwant(key, (err) => { - expect(err).to.not.exist() - done() + it('.wantlist', (done) => { + ipfs.bitswap.wantlist((err, res) => { + expect(err).to.not.exist() + expect(res).to.have.to.eql({ + Keys: null }) + done() }) }) - describe('Promise API', () => { - it('.wantlist', () => { - return ipfs.bitswap.wantlist() - .then((res) => { - expect(res).to.have.to.be.eql({ - Keys: null - }) - }) - }) + it('.stat', (done) => { + ipfs.bitswap.stat((err, res) => { + expect(err).to.not.exist() + expect(res).to.have.property('BlocksReceived') + expect(res).to.have.property('DupBlksReceived') + expect(res).to.have.property('DupDataReceived') + expect(res).to.have.property('Peers') + expect(res).to.have.property('ProvideBufLen') + expect(res).to.have.property('Wantlist') - it('.stat', () => { - return ipfs.bitswap.stat() - .then((res) => { - expect(res).to.have.property('BlocksReceived') - expect(res).to.have.property('DupBlksReceived') - expect(res).to.have.property('DupDataReceived') - expect(res).to.have.property('Peers') - expect(res).to.have.property('ProvideBufLen') - expect(res).to.have.property('Wantlist') - }) + done() }) + }) - it('.unwant', () => { - const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - return ipfs.bitswap.unwant(key) + it('.unwant', (done) => { + const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + ipfs.bitswap.unwant(key, (err) => { + expect(err).to.not.exist() + done() }) }) }) diff --git a/test/bootstrap.spec.js b/test/bootstrap.spec.js index 65b053485..4cc7e3221 100644 --- a/test/bootstrap.spec.js +++ b/test/bootstrap.spec.js @@ -6,7 +6,11 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const invalidArg = 'this/Is/So/Invalid/' const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' @@ -14,21 +18,19 @@ const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrS describe('.bootstrap', function () { this.timeout(100 * 1000) + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) let peers diff --git a/test/commands.spec.js b/test/commands.spec.js index 5962d47fb..5e2b3804d 100644 --- a/test/commands.spec.js +++ b/test/commands.spec.js @@ -6,26 +6,27 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.commands', function () { this.timeout(20 * 1000) + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) it('lists commands', (done) => { ipfs.commands((err, res) => { diff --git a/test/constructor.spec.js b/test/constructor.spec.js index a210d1e36..46ef3fb3e 100644 --- a/test/constructor.spec.js +++ b/test/constructor.spec.js @@ -5,7 +5,9 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const ipfsAPI = require('../src/index.js') @@ -22,19 +24,19 @@ function clientWorks (client, done) { describe('ipfs-api constructor tests', () => { describe('parameter permuations', () => { let apiAddr - let fc + let ipfsd before(function (done) { this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - apiAddr = node.apiAddr + ipfsd = node + apiAddr = node.apiAddr.toString() done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) it('opts', (done) => { const splitted = apiAddr.split('/') diff --git a/test/diag.spec.js b/test/diag.spec.js index ca88ba225..5f68a3e95 100644 --- a/test/diag.spec.js +++ b/test/diag.spec.js @@ -1,13 +1,17 @@ /* eslint-env mocha */ 'use strict' -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const os = require('os') +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('.diag', function () { this.timeout(50 * 1000) @@ -16,19 +20,19 @@ describe('.diag', function () { return } + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) describe('Callback API', () => { // Disabled in go-ipfs 0.4.10 diff --git a/test/files.spec.js b/test/files.spec.js index c1ccc56d1..3a9425d56 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -11,7 +11,10 @@ const loadFixture = require('aegir/fixtures') const mh = require('multihashes') const CID = require('cids') -const FactoryClient = require('./ipfs-factory/client') +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const testfile = isNode ? loadFixture(__dirname, '/fixtures/testfile.txt') @@ -32,21 +35,21 @@ const HASH_ALGS = [ describe('.files (the MFS API part)', function () { this.timeout(120 * 1000) + let ipfsd let ipfs - let fc const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) describe('Callback API', function () { this.timeout(120 * 1000) diff --git a/test/fixtures/test-folder/hello-link b/test/fixtures/test-folder/hello-link deleted file mode 100644 index 50b07e9e7..000000000 --- a/test/fixtures/test-folder/hello-link +++ /dev/null @@ -1 +0,0 @@ -files/hello.txt \ No newline at end of file diff --git a/test/fixtures/test-folder/hello-link b/test/fixtures/test-folder/hello-link new file mode 120000 index 000000000..50b07e9e7 --- /dev/null +++ b/test/fixtures/test-folder/hello-link @@ -0,0 +1 @@ +files/hello.txt \ No newline at end of file diff --git a/test/get.spec.js b/test/get.spec.js index 008905bba..3cd9e99c6 100644 --- a/test/get.spec.js +++ b/test/get.spec.js @@ -10,7 +10,11 @@ chai.use(dirtyChai) const isNode = require('detect-node') const series = require('async/series') const loadFixture = require('aegir/fixtures') -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.get (specific go-ipfs features)', function () { this.timeout(20 * 1000) @@ -24,23 +28,22 @@ describe('.get (specific go-ipfs features)', function () { data: fixture('../test/fixtures/testfile.txt') } + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - series([ - (cb) => fc.spawnNode((err, node) => { + (cb) => df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) cb() }), (cb) => ipfs.files.add(smallFile.data, cb) ], done) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) it('no compression args', (done) => { ipfs.get(smallFile.cid, (err, files) => { @@ -78,7 +81,9 @@ describe('.get (specific go-ipfs features)', function () { }) it('add path containing "+"s (for testing get)', (done) => { - if (!isNode) { return done() } + if (!isNode) { + return done() + } const filename = 'ti,c64x+mega++mod-pic.txt' const subdir = 'tmp/c++files' @@ -94,7 +99,9 @@ describe('.get (specific go-ipfs features)', function () { }) it('get path containing "+"s', (done) => { - if (!isNode) { return done() } + if (!isNode) { + return done() + } const cid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff' let count = 0 diff --git a/test/interface/block.spec.js b/test/interface/block.spec.js index ce96664dc..5a1883088 100644 --- a/test/interface/block.spec.js +++ b/test/interface/block.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const Factory = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let factory +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - factory = new Factory() - callback(null, factory) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - factory.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/config.spec.js b/test/interface/config.spec.js index 0527c954e..91f551a7d 100644 --- a/test/interface/config.spec.js +++ b/test/interface/config.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/dht.spec.js b/test/interface/dht.spec.js index b1e731e77..1ae3081fc 100644 --- a/test/interface/dht.spec.js +++ b/test/interface/dht.spec.js @@ -2,17 +2,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/files.spec.js b/test/interface/files.spec.js index 8170ce597..c58b9d5e8 100644 --- a/test/interface/files.spec.js +++ b/test/interface/files.spec.js @@ -3,18 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') -const FactoryClient = require('../ipfs-factory/client') +const IPFSApi = require('../../src') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/generic.spec.js b/test/interface/generic.spec.js index 2e4403c60..31a6e66e8 100644 --- a/test/interface/generic.spec.js +++ b/test/interface/generic.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/key.spec.js b/test/interface/key.spec.js index 1f285895d..6fd3510f5 100644 --- a/test/interface/key.spec.js +++ b/test/interface/key.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const Factory = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let factory +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - factory = new Factory() - callback(null, factory) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - factory.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/object.spec.js b/test/interface/object.spec.js index ea127d09c..be4ffa70c 100644 --- a/test/interface/object.spec.js +++ b/test/interface/object.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/pin.spec.js b/test/interface/pin.spec.js index b841568ac..d72d008b3 100644 --- a/test/interface/pin.spec.js +++ b/test/interface/pin.spec.js @@ -3,17 +3,31 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/pubsub.spec.js b/test/interface/pubsub.spec.js index 5448ccc97..4499bcbce 100644 --- a/test/interface/pubsub.spec.js +++ b/test/interface/pubsub.spec.js @@ -3,19 +3,35 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') const isNode = require('detect-node') -if (isNode) { - let fc +const parallel = require('async/parallel') + +const IPFSApi = require('../../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() +if (isNode) { + const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + callback(null, { + spawnNode: (cb) => { + df.spawn({ args: ['--enable-pubsub-experiment'] }, + (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/interface/swarm.spec.js b/test/interface/swarm.spec.js index 420f08543..6d04fbcd8 100644 --- a/test/interface/swarm.spec.js +++ b/test/interface/swarm.spec.js @@ -3,17 +3,41 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../ipfs-factory/client') +const parallel = require('async/parallel') -let fc +const IPFSApi = require('../../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) + 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 }, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) }, teardown: function (callback) { - fc.dismantle(callback) + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/ipfs-factory/client.js b/test/ipfs-factory/client.js deleted file mode 100644 index a3df65e0e..000000000 --- a/test/ipfs-factory/client.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict' - -const io = require('socket.io-client') -const ipfsAPI = require('../../src') - -module.exports = Factory - -function Factory () { - if (!(this instanceof Factory)) { - return new Factory() - } - const sioOptions = { - transports: ['websocket'], - 'force new connection': true - } - const sioUrl = 'http://localhost:55155' - let sioConnected = false - let ioC - - this.spawnNode = (repoPath, config, callback) => { - if (typeof repoPath === 'function') { - callback = repoPath - repoPath = undefined - } - if (typeof config === 'function') { - callback = config - config = undefined - } - - if (sioConnected) { - spawnNode() - } else { - ioC = io.connect(sioUrl, sioOptions) - ioC.once('error', callback) - ioC.once('connect_error', callback) - ioC.once('connect', () => { - sioConnected = true - spawnNode() - }) - } - - function spawnNode () { - ioC.once('fc-node', (apiAddr) => { - const ipfs = ipfsAPI(apiAddr) - ipfs.apiAddr = apiAddr - callback(null, ipfs) - }) - ioC.emit('fs-spawn-node', repoPath, config) - } - } - - this.dismantle = function (callback) { - ioC.once('fc-nodes-shutdown', (err) => { - ioC.disconnect() - sioConnected = false - callback(err) - }) - ioC.emit('fs-dismantle') - } -} diff --git a/test/ipfs-factory/daemon-spawner.js b/test/ipfs-factory/daemon-spawner.js deleted file mode 100644 index 0d861c402..000000000 --- a/test/ipfs-factory/daemon-spawner.js +++ /dev/null @@ -1,90 +0,0 @@ -'use strict' - -const ipfsd = require('ipfsd-ctl') -const series = require('async/series') -const eachSeries = require('async/eachSeries') -const once = require('once') - -module.exports = Factory - -function Factory () { - if (!(this instanceof Factory)) { - return new Factory() - } - - let nodes = [] - - this.spawnNode = (repoPath, config, callback) => { - if (typeof repoPath === 'function') { - callback = repoPath - repoPath = undefined - } - if (typeof config === 'function') { - callback = config - config = undefined - } - - // TODO - // support custom repoPath - // support custom configs being passed - - spawnEphemeralNode((err, node) => { - if (err) { - return callback(err) - } - - nodes.push(node) - - callback(null, node.apiAddr) - }) - } - - this.dismantle = (callback) => { - eachSeries(nodes, (node, cb) => { - cb = once(cb) - node.stopDaemon(cb) - }, (err) => { - if (err) { - return callback(err) - } - - nodes = [] - - callback() - }) - } -} - -function spawnEphemeralNode (callback) { - ipfsd.disposable((err, node) => { - if (err) { - return callback(err) - } - - // Note: we have to set each config value - // independently since the config/replace endpoint - // doesn't work as expected - series([ - (cb) => { - const configValues = { - Bootstrap: [], - Discovery: {}, - 'API.HTTPHeaders.Access-Control-Allow-Origin': ['*'], - // This is not needed after all - // 'API.HTTPHeaders.Access-Control-Allow-Credentials': true, - 'API.HTTPHeaders.Access-Control-Allow-Methods': [ - 'PUT', - 'POST', - 'GET' - ] - } - - eachSeries(Object.keys(configValues), (configKey, cb) => { - const configVal = JSON.stringify(configValues[configKey]) - node.setConfig(configKey, configVal, cb) - }, cb) - }, - (cb) => node.startDaemon(['--enable-pubsub-experiment'], cb) - ], (err) => callback(err, node)) - }) -} diff --git a/test/ipfs-factory/server-routes.js b/test/ipfs-factory/server-routes.js deleted file mode 100644 index 31c60019a..000000000 --- a/test/ipfs-factory/server-routes.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict' - -const SocketIO = require('socket.io') -const DaemonSpawner = require('./daemon-spawner') - -module.exports = (http) => { - const io = new SocketIO(http.listener) - io.on('connection', handle) - io.on('error', (err) => this.emit('error', err)) - - const ds = new DaemonSpawner() - - function handle (socket) { - socket.on('fs-spawn-node', spawnNode.bind(socket)) - socket.on('fs-dismantle', dismantle.bind(socket)) - } - - function spawnNode (repoPath, config) { - ds.spawnNode(repoPath, config, (err, apiAddr) => { - if (err) { - return this.emit('error', err) - } - this.emit('fc-node', apiAddr.toString()) - }) - } - - function dismantle () { - ds.dismantle((err) => { - if (err) { - return this.emit('error', err) - } - this.emit('fc-nodes-shutdown') - }) - } -} diff --git a/test/ipfs-factory/server.js b/test/ipfs-factory/server.js deleted file mode 100644 index 9f4663334..000000000 --- a/test/ipfs-factory/server.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' - -const Hapi = require('hapi') - -const port = Number(process.env.PORT) || 55155 -const options = { - connections: { - routes: { - cors: true - } - } -} - -module.exports = (callback) => { - const http = new Hapi.Server(options) - - http.connection({ port: port }) - - http.start((err) => { - if (err) { - return callback(err) - } - require('./server-routes')(http) - - callback(null, http) - // note: http.stop(callback) to stop the server :) - }) -} diff --git a/test/ipfs-factory/tasks.js b/test/ipfs-factory/tasks.js deleted file mode 100644 index eca18f8f3..000000000 --- a/test/ipfs-factory/tasks.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict' - -const factoryServer = require('./server') - -let factory - -module.exports = { - start (done) { - factoryServer((err, http) => { - if (err) { - return done(err) - } - factory = http - done() - }) - }, - stop (done) { - factory.stop({ - timeout: 1 - }, done) - } -} diff --git a/test/key.spec.js b/test/key.spec.js index f3bbaf7ef..3db9a9953 100644 --- a/test/key.spec.js +++ b/test/key.spec.js @@ -2,30 +2,32 @@ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('.key', function () { this.timeout(50 * 1000) + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) describe('Callback API', () => { describe('.gen', () => { @@ -61,13 +63,13 @@ describe('.key', function () { describe('Promise API', () => { describe('.gen', () => { it('create a new rsa key', () => { - return ipfs.key.gen('foobarsa2', {type: 'rsa', size: 2048}).then((res) => { + return ipfs.key.gen('foobarsa2', { type: 'rsa', size: 2048 }).then((res) => { expect(res).to.exist() }) }) it('create a new ed25519 key', () => { - return ipfs.key.gen('bazed2', {type: 'ed25519'}).then((res) => { + return ipfs.key.gen('bazed2', { type: 'ed25519' }).then((res) => { expect(res).to.exist() }) }) diff --git a/test/log.spec.js b/test/log.spec.js index 24d4fe11c..38dc7d710 100644 --- a/test/log.spec.js +++ b/test/log.spec.js @@ -6,24 +6,28 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.log', function () { this.timeout(100 * 1000) + let ipfsd let ipfs - let fc before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) describe('Callback API', function () { this.timeout(100 * 1000) diff --git a/test/name.spec.js b/test/name.spec.js index 4e2330e51..4cf1088f9 100644 --- a/test/name.spec.js +++ b/test/name.spec.js @@ -5,10 +5,16 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) + +const parallel = require('async/parallel') const isNode = require('detect-node') const series = require('async/series') const loadFixture = require('aegir/fixtures') -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const testfile = isNode ? loadFixture(__dirname, '/fixtures/testfile.txt') @@ -18,28 +24,30 @@ describe('.name', function () { this.timeout(50 * 1000) let ipfs + let ipfsd let other - let fc + let otherd before((done) => { - fc = new FactoryClient() series([ (cb) => { - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) cb() }) }, (cb) => { - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - other = node + other = node.api + otherd = node cb() }) }, (cb) => { - ipfs.id((err, id) => { + ipfsd.api.id((err, id) => { expect(err).to.not.exist() const ma = id.addresses[0] other.swarm.connect(ma, cb) @@ -48,7 +56,12 @@ describe('.name', function () { ], done) }) - after((done) => fc.dismantle(done)) + after((done) => { + parallel([ + (cb) => ipfsd.stop(cb), + (cb) => otherd.stop(cb) + ], done) + }) describe('Callback API', () => { let name @@ -66,7 +79,8 @@ describe('.name', function () { }) }) - it('.name.publish', (done) => { + it('.name.publish', function (done) { + this.timeout(100 * 1000) ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { expect(err).to.not.exist() name = res @@ -88,7 +102,8 @@ describe('.name', function () { describe('Promise API', () => { let name - it('.name.publish', () => { + it('.name.publish', function () { + this.timeout(80 * 1000) return ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') .then((res) => { name = res diff --git a/test/ping.spec.js b/test/ping.spec.js index af287431c..e2bcc44ff 100644 --- a/test/ping.spec.js +++ b/test/ping.spec.js @@ -6,44 +6,56 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const parallel = require('async/parallel') const series = require('async/series') -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe.skip('.ping', () => { let ipfs + let ipfsd let other - let fc + let otherd before(function (done) { this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() series([ (cb) => { - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) cb() }) }, (cb) => { console.log('going to spawn second node') - fc.spawnNode((err, node) => { + df.spawn((err, node) => { expect(err).to.not.exist() - other = node + other = node.api + otherd = node cb() }) }, (cb) => { - ipfs.id((err, id) => { + ipfsd.api.id((err, id) => { expect(err).to.not.exist() const ma = id.addresses[0] - other.swarm.connect(ma, cb) + other.api.swarm.connect(ma, cb) }) } ], done) }) - after((done) => fc.dismantle(done)) + after((done) => { + parallel([ + (cb) => ipfsd.stop(cb), + (cb) => otherd.stop(cb) + ], done) + }) describe('callback API', () => { it('ping another peer', (done) => { diff --git a/test/pubsub-in-browser.spec.js b/test/pubsub-in-browser.spec.js index b6efe9f5c..818b477bb 100644 --- a/test/pubsub-in-browser.spec.js +++ b/test/pubsub-in-browser.spec.js @@ -26,29 +26,18 @@ /* eslint max-nested-callbacks: ['error', 8] */ 'use strict' -const series = require('async/series') -const waterfall = require('async/waterfall') const isNode = require('detect-node') -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const expectedError = 'pubsub is currently not supported when run in the browser' +const IPFSApi = require('../src') -function spawnWithId (factory, callback) { - waterfall([ - (cb) => factory.spawnNode(cb), - (node, cb) => node.id((err, res) => { - if (err) { - return cb(err) - } - node.peerId = res - cb(null, node) - }) - ], callback) -} +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const expectedError = 'pubsub is currently not supported when run in the browser' describe('.pubsub-browser (pubsub not supported in the browsers currently)', function () { this.timeout(50 * 1000) @@ -59,33 +48,25 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun } const topic = 'pubsub-tests' - let factory - let ipfs1 + let ipfs + let ipfsd before((done) => { - factory = new FactoryClient() - - series([ - (cb) => spawnWithId(factory, cb) - ], (err, nodes) => { - if (err) { - return done(err) - } - - ipfs1 = nodes[0] + df.spawn((err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - factory.dismantle(done) - }) + after((done) => ipfsd.stop(done)) describe('everything errors', () => { describe('Callback API', () => { describe('.publish', () => { it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.publish(topic, 'hello friend', (err, topics) => { + ipfs.pubsub.publish(topic, 'hello friend', (err, topics) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() @@ -96,7 +77,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.subscribe', () => { const handler = () => {} it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.subscribe(topic, {}, handler, (err, topics) => { + ipfs.pubsub.subscribe(topic, {}, handler, (err, topics) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() @@ -106,7 +87,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.peers', () => { it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.peers(topic, (err, topics) => { + ipfs.pubsub.peers(topic, (err, topics) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() @@ -116,7 +97,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.ls', () => { it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.ls((err, topics) => { + ipfs.pubsub.ls((err, topics) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) done() @@ -128,7 +109,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('Promise API', () => { describe('.publish', () => { it('throws an error if called in the browser', () => { - return ipfs1.pubsub.publish(topic, 'hello friend') + return ipfs.pubsub.publish(topic, 'hello friend') .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) @@ -139,7 +120,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.subscribe', () => { const handler = () => {} it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.subscribe(topic, {}, handler) + ipfs.pubsub.subscribe(topic, {}, handler) .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) @@ -150,7 +131,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.peers', () => { it('throws an error if called in the browser', (done) => { - ipfs1.pubsub.peers(topic) + ipfs.pubsub.peers(topic) .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) @@ -161,7 +142,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.ls', () => { it('throws an error if called in the browser', () => { - return ipfs1.pubsub.ls() + return ipfs.pubsub.ls() .catch((err) => { expect(err).to.exist() expect(err.message).to.equal(expectedError) @@ -173,7 +154,7 @@ describe('.pubsub-browser (pubsub not supported in the browsers currently)', fun describe('.unsubscribe', () => { it('throws an error if called in the browser', (done) => { try { - ipfs1.pubsub.unsubscribe() + ipfs.pubsub.unsubscribe() done('unsubscribe() didn\'t throw an error') } catch (err) { expect(err).to.exist() diff --git a/test/refs.spec.js b/test/refs.spec.js index b004db6de..d6ca6572d 100644 --- a/test/refs.spec.js +++ b/test/refs.spec.js @@ -8,20 +8,25 @@ chai.use(dirtyChai) const isNode = require('detect-node') const waterfall = require('async/waterfall') const path = require('path') -const FactoryClient = require('./ipfs-factory/client') const fs = require('fs') +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('.refs', function () { this.timeout(80 * 1000) - if (!isNode) { return } + if (!isNode) { + return + } let ipfs - let fc + let ipfsd let folder before((done) => { - fc = new FactoryClient() const filesPath = path.join(__dirname, '/fixtures/test-folder') // Symlinks in a repo don't always clone well, especially on Windows. @@ -34,9 +39,10 @@ describe('.refs', function () { } waterfall([ - (cb) => fc.spawnNode(cb), - (node, cb) => { - ipfs = node + (cb) => df.spawn(cb), + (_ipfsd, cb) => { + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) ipfs.util.addFromFs(filesPath, { recursive: true }, cb) }, (hashes, cb) => { @@ -47,7 +53,7 @@ describe('.refs', function () { ], done) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) const result = [ { @@ -86,7 +92,7 @@ describe('.refs', function () { describe('Promise API', () => { it('refs', () => { - return ipfs.refs(folder, {format: ' '}) + return ipfs.refs(folder, { format: ' ' }) .then((objs) => { expect(objs).to.eql(result) }) diff --git a/test/repo.spec.js b/test/repo.spec.js index 0af2a0001..9507918de 100644 --- a/test/repo.spec.js +++ b/test/repo.spec.js @@ -1,30 +1,32 @@ /* eslint-env mocha */ 'use strict' -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('.repo', function () { this.timeout(50 * 1000) // slow CI let ipfs - let fc + let ipfsd before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => ipfsd.stop(done)) describe('Callback API', () => { it('.repo.gc', (done) => { diff --git a/test/stats.spec.js b/test/stats.spec.js index 8775d88ed..1f1619157 100644 --- a/test/stats.spec.js +++ b/test/stats.spec.js @@ -1,113 +1,72 @@ /* eslint-env mocha */ 'use strict' -const FactoryClient = require('./ipfs-factory/client') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + describe('stats', function () { this.timeout(50 * 1000) // slow CI let ipfs - let fc + let ipfsd before((done) => { - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => { - fc.dismantle(done) - }) - - describe('Callback API', () => { - it('.stats.bitswap', (done) => { - ipfs.stats.bitswap((err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.a.property('provideBufLen') - expect(res).to.have.a.property('wantlist') - expect(res).to.have.a.property('peers') - expect(res).to.have.a.property('blocksReceived') - expect(res).to.have.a.property('dataReceived') - expect(res).to.have.a.property('blocksSent') - expect(res).to.have.a.property('dataSent') - expect(res).to.have.a.property('dupBlksReceived') - expect(res).to.have.a.property('dupDataReceived') - done() - }) - }) - - it('.stats.bw', (done) => { - ipfs.stats.bw((err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.a.property('totalIn') - expect(res).to.have.a.property('totalOut') - expect(res).to.have.a.property('rateIn') - expect(res).to.have.a.property('rateOut') - done() - }) - }) + after((done) => ipfsd.stop(done)) - it('.stats.repo', (done) => { - ipfs.stats.repo((err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.a.property('numObjects') - expect(res).to.have.a.property('repoSize') - expect(res).to.have.a.property('repoPath') - expect(res).to.have.a.property('version') - expect(res).to.have.a.property('storageMax') - done() - }) + it('.stats.bitswap', (done) => { + ipfs.stats.bitswap((err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res).to.have.a.property('provideBufLen') + expect(res).to.have.a.property('wantlist') + expect(res).to.have.a.property('peers') + expect(res).to.have.a.property('blocksReceived') + expect(res).to.have.a.property('dataReceived') + expect(res).to.have.a.property('blocksSent') + expect(res).to.have.a.property('dataSent') + expect(res).to.have.a.property('dupBlksReceived') + expect(res).to.have.a.property('dupDataReceived') + done() }) }) - describe('Promise API', () => { - it('.stats.bw', () => { - return ipfs.stats.bw() - .then((res) => { - expect(res).to.exist() - expect(res).to.have.a.property('totalIn') - expect(res).to.have.a.property('totalOut') - expect(res).to.have.a.property('rateIn') - expect(res).to.have.a.property('rateOut') - }) - }) - - it('.stats.repo', () => { - return ipfs.stats.repo() - .then((res) => { - expect(res).to.exist() - expect(res).to.have.a.property('numObjects') - expect(res).to.have.a.property('repoSize') - expect(res).to.have.a.property('repoPath') - expect(res).to.have.a.property('version') - expect(res).to.have.a.property('storageMax') - }) + it('.stats.bw', (done) => { + ipfs.stats.bw((err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res).to.have.a.property('totalIn') + expect(res).to.have.a.property('totalOut') + expect(res).to.have.a.property('rateIn') + expect(res).to.have.a.property('rateOut') + done() }) + }) - it('.stats.bitswap', () => { - return ipfs.stats.bitswap() - .then((res) => { - expect(res).to.exist() - expect(res).to.have.a.property('provideBufLen') - expect(res).to.have.a.property('wantlist') - expect(res).to.have.a.property('peers') - expect(res).to.have.a.property('blocksReceived') - expect(res).to.have.a.property('dataReceived') - expect(res).to.have.a.property('blocksSent') - expect(res).to.have.a.property('dataSent') - expect(res).to.have.a.property('dupBlksReceived') - expect(res).to.have.a.property('dupDataReceived') - }) + it('.stats.repo', (done) => { + ipfs.stats.repo((err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res).to.have.a.property('numObjects') + expect(res).to.have.a.property('repoSize') + expect(res).to.have.a.property('repoPath') + expect(res).to.have.a.property('version') + expect(res).to.have.a.property('storageMax') + done() }) }) }) diff --git a/test/util.spec.js b/test/util.spec.js index e0a43d7d0..89b81414b 100644 --- a/test/util.spec.js +++ b/test/util.spec.js @@ -9,26 +9,30 @@ chai.use(dirtyChai) const isNode = require('detect-node') const path = require('path') const fs = require('fs') -const FactoryClient = require('./ipfs-factory/client') + +const IPFSApi = require('../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe('.util', () => { if (!isNode) { return } + let ipfsd let ipfs - let fc before(function (done) { this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { + df.spawn((err, _ipfsd) => { expect(err).to.not.exist() - ipfs = node + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) done() }) }) - after((done) => fc.dismantle(done)) + after((done) => ipfsd.stop(done)) it('.streamAdd', (done) => { const tfpath = path.join(__dirname, '/fixtures/testfile.txt') From ecf70b93570e1f01eac7675569134595183f2fc9 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 23 Jan 2018 19:33:30 -0500 Subject: [PATCH 5/8] feat: /api/v0/repo/version (#676) --- src/repo/index.js | 3 ++- src/repo/version.js | 16 ++++++++++++++++ test/repo.spec.js | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/repo/version.js diff --git a/src/repo/index.js b/src/repo/index.js index c70098d35..d3ac72785 100644 --- a/src/repo/index.js +++ b/src/repo/index.js @@ -7,6 +7,7 @@ module.exports = (arg) => { return { gc: require('./gc')(send), - stat: require('./stat')(send) + stat: require('./stat')(send), + version: require('./version')(send) } } diff --git a/src/repo/version.js b/src/repo/version.js new file mode 100644 index 000000000..0b49f78c6 --- /dev/null +++ b/src/repo/version.js @@ -0,0 +1,16 @@ +'use strict' + +const promisify = require('promisify-es6') + +module.exports = (send) => { + return promisify((opts, callback) => { + if (typeof (opts) === 'function') { + callback = opts + opts = {} + } + send({ + path: 'repo/version', + qs: opts + }, callback) + }) +} diff --git a/test/repo.spec.js b/test/repo.spec.js index 9507918de..b0b4fce9f 100644 --- a/test/repo.spec.js +++ b/test/repo.spec.js @@ -46,6 +46,15 @@ describe('.repo', function () { done() }) }) + + it('.repo.version', (done) => { + ipfs.repo.version((err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res).to.have.a.property('Version') + done() + }) + }) }) describe('Promise API', () => { @@ -61,5 +70,13 @@ describe('.repo', function () { expect(res).to.have.a.property('RepoSize') }) }) + + it('.repo.version', () => { + return ipfs.repo.version() + .then(res => { + expect(res).to.exist() + expect(res).to.have.a.property('Version') + }) + }) }) }) From fe640bca0fa948262d366665040643de6a0c779b Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 23 Jan 2018 16:42:26 -0800 Subject: [PATCH 6/8] chore: release version v17.4.0 --- CHANGELOG.md | 15 +++++++++++++++ package.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df877ddf9..481774d2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ + +# [17.4.0](https://github.com/ipfs/js-ipfs-api/compare/v17.3.0...v17.4.0) (2018-01-24) + + +### Bug Fixes + +* normalize stats fields ([#669](https://github.com/ipfs/js-ipfs-api/issues/669)) ([5803d39](https://github.com/ipfs/js-ipfs-api/commit/5803d39)) + + +### Features + +* integrate new ipfsd-ctl ([2b1820b](https://github.com/ipfs/js-ipfs-api/commit/2b1820b)) + + + # [17.3.0](https://github.com/ipfs/js-ipfs-api/compare/v17.2.7...v17.3.0) (2018-01-12) diff --git a/package.json b/package.json index 58ab6abdd..53dab6eeb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-api", - "version": "17.3.0", + "version": "17.4.0", "description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec", "main": "src/index.js", "browser": { From 45b5aebfd79a7b3c4f8fcfaef9aba626c57f72d0 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 23 Jan 2018 16:46:42 -0800 Subject: [PATCH 7/8] chore: update contributors --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 53dab6eeb..a2960f47e 100644 --- a/package.json +++ b/package.json @@ -110,6 +110,7 @@ "Jeromy ", "Jeromy ", "Joe Turgeon ", + "Jonathan ", "Juan Batiz-Benet ", "Kevin Wang ", "Kristoffer Ström ", From 12e23ee5b6c1ed2ed9612b9b43b0d9392b95c149 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 23 Jan 2018 16:46:42 -0800 Subject: [PATCH 8/8] chore: release version v17.5.0 --- CHANGELOG.md | 16 ++++++++++++++++ package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 481774d2f..0909c0811 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ + +# [17.5.0](https://github.com/ipfs/js-ipfs-api/compare/v17.3.0...v17.5.0) (2018-01-24) + + +### Bug Fixes + +* normalize stats fields ([#669](https://github.com/ipfs/js-ipfs-api/issues/669)) ([5803d39](https://github.com/ipfs/js-ipfs-api/commit/5803d39)) + + +### Features + +* /api/v0/repo/version ([#676](https://github.com/ipfs/js-ipfs-api/issues/676)) ([ecf70b9](https://github.com/ipfs/js-ipfs-api/commit/ecf70b9)) +* integrate new ipfsd-ctl ([2b1820b](https://github.com/ipfs/js-ipfs-api/commit/2b1820b)) + + + # [17.4.0](https://github.com/ipfs/js-ipfs-api/compare/v17.3.0...v17.4.0) (2018-01-24) diff --git a/package.json b/package.json index a2960f47e..682121c88 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-api", - "version": "17.4.0", + "version": "17.5.0", "description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec", "main": "src/index.js", "browser": {