From ddf9504ad9fd028c65f4d754266ee909c4ecc20c Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 31 Jan 2018 18:53:19 -0500 Subject: [PATCH 01/10] add --only-hash flag --- src/cli/commands/files/add.js | 12 +++++++++--- src/core/components/files.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index 5886ac2365..90927a9a69 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -139,6 +139,12 @@ module.exports = { type: 'boolean', default: false }, + 'only-hash': { + alias: 'n', + type: 'boolean', + default: false, + describe: 'Only chunk and hash, do not write to disk' + }, 'enable-sharding-experiment': { type: 'boolean', default: false @@ -182,7 +188,8 @@ module.exports = { strategy: argv.trickle ? 'trickle' : 'balanced', shardSplitThreshold: argv.enableShardingExperiment ? argv.shardSplitThreshold : Infinity, 'cid-version': argv['cid-version'], - 'raw-leaves': argv['raw-leaves'] + 'raw-leaves': argv['raw-leaves'], + onlyHash: argv.onlyHash } // Temporary restriction on raw-leaves: @@ -230,8 +237,7 @@ module.exports = { } } - const thing = (cb) => cb(null, ipfs.files.addPullStream(options)) - thing(next) + next(null, ipfs.files.addPullStream(options)) } ], (err, addStream) => { if (err) throw err diff --git a/src/core/components/files.js b/src/core/components/files.js index 5906487570..4c66d954e0 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -23,7 +23,7 @@ function prepareFile (self, opts, file, callback) { opts = opts || {} waterfall([ - (cb) => self.object.get(file.multihash, cb), + (cb) => opts.onlyHash ? cb(null, file) : self.object.get(file.multihash, cb), (node, cb) => { let cid = new CID(node.multihash) From db7b99537a7a211db7a7e872520bddc44ea7cbc3 Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 31 Jan 2018 18:54:13 -0500 Subject: [PATCH 02/10] skeleton http option passing, checkpoint commit to check some broken tests. --- src/http/api/resources/files.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 55c406d86c..0cab4285ea 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -205,8 +205,10 @@ exports.add = { const options = { 'cid-version': request.query['cid-version'], 'raw-leaves': request.query['raw-leaves'], - progress: request.query['progress'] ? progressHandler : null + progress: request.query['progress'] ? progressHandler : null, + onlyHash: request.query['only-hash'] } + console.log('http options:', options) const aborter = abortable() const stream = toStream.source(pull( From 855d1e90714fea6f757db250713a4bf6e7947ec1 Mon Sep 17 00:00:00 2001 From: jkrone Date: Fri, 2 Feb 2018 15:11:48 -0500 Subject: [PATCH 03/10] deep logging for debugging. Checkpoint --- src/http/index.js | 7 ++++++- test/http-api/extra/version.js | 22 ++++++++++++++++++++++ test/http-api/inject/bitswap.js | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/http-api/extra/version.js diff --git a/src/http/index.js b/src/http/index.js index 4a985ce3c6..58056c7e18 100644 --- a/src/http/index.js +++ b/src/http/index.js @@ -74,7 +74,9 @@ function HttpApi (repo, config, cliArgs) { }, libp2p: libp2p }) + this.log('starting the daemon') } catch (err) { + this.log.error('failed to start the daemon') return cb(err) } @@ -83,7 +85,10 @@ function HttpApi (repo, config, cliArgs) { err.code = 'ENOENT' cb(err) }) - this.node.once('start', cb) + this.node.once('start', () => { + this.log('started core') + cb(arguments) + }) }, (cb) => { this.log('fetching config') diff --git a/test/http-api/extra/version.js b/test/http-api/extra/version.js new file mode 100644 index 0000000000..8dd96d9255 --- /dev/null +++ b/test/http-api/extra/version.js @@ -0,0 +1,22 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + +module.exports = (ctl) => { + describe('.version', () => { + it('get the version', (done) => { + ctl.version((err, result) => { + console.log('Success! version results:', result) + expect(err).to.not.exist() + expect(result).to.have.a.property('version') + expect(result).to.have.a.property('commit') + expect(result).to.have.a.property('repo') + done() + }) + }) + }) +} diff --git a/test/http-api/inject/bitswap.js b/test/http-api/inject/bitswap.js index 16e2c6ceef..fddc15d970 100644 --- a/test/http-api/inject/bitswap.js +++ b/test/http-api/inject/bitswap.js @@ -11,7 +11,7 @@ module.exports = (http) => { api = http.api.server.select('API') }) - it('/wantlist', (done) => { + it.only('/wantlist', (done) => { api.inject({ method: 'GET', url: '/api/v0/bitswap/wantlist' From c5309ea00252b990dad56647f8fe3091ae0029bd Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 20 Feb 2018 13:01:39 -0500 Subject: [PATCH 04/10] found the levledown problem! line endings! --- src/http/index.js | 7 +------ test/http-api/extra/version.js | 2 +- test/http-api/inject/bitswap.js | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/http/index.js b/src/http/index.js index 58056c7e18..4a985ce3c6 100644 --- a/src/http/index.js +++ b/src/http/index.js @@ -74,9 +74,7 @@ function HttpApi (repo, config, cliArgs) { }, libp2p: libp2p }) - this.log('starting the daemon') } catch (err) { - this.log.error('failed to start the daemon') return cb(err) } @@ -85,10 +83,7 @@ function HttpApi (repo, config, cliArgs) { err.code = 'ENOENT' cb(err) }) - this.node.once('start', () => { - this.log('started core') - cb(arguments) - }) + this.node.once('start', cb) }, (cb) => { this.log('fetching config') diff --git a/test/http-api/extra/version.js b/test/http-api/extra/version.js index 8dd96d9255..08552f0d3d 100644 --- a/test/http-api/extra/version.js +++ b/test/http-api/extra/version.js @@ -8,7 +8,7 @@ chai.use(dirtyChai) module.exports = (ctl) => { describe('.version', () => { - it('get the version', (done) => { + it.only('gets the version', (done) => { ctl.version((err, result) => { console.log('Success! version results:', result) expect(err).to.not.exist() diff --git a/test/http-api/inject/bitswap.js b/test/http-api/inject/bitswap.js index fddc15d970..16e2c6ceef 100644 --- a/test/http-api/inject/bitswap.js +++ b/test/http-api/inject/bitswap.js @@ -11,7 +11,7 @@ module.exports = (http) => { api = http.api.server.select('API') }) - it.only('/wantlist', (done) => { + it('/wantlist', (done) => { api.inject({ method: 'GET', url: '/api/v0/bitswap/wantlist' From 545c122f119f7d5292fedac5ed3fc8769534535d Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 21 Feb 2018 17:14:16 -0500 Subject: [PATCH 05/10] add only-hash as a qs option for the send-files-stream. Also added some tests to help me figure that out --- src/cli/commands/files/add.js | 2 +- src/http/api/resources/files.js | 9 +++++---- test/cli/files.js | 16 ++++++++++++++++ test/http-api/extra/files.js | 27 +++++++++++++++++++++++++++ test/http-api/extra/version.js | 12 ++++-------- 5 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 test/http-api/extra/files.js diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index 90927a9a69..bcf43a554d 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -189,7 +189,7 @@ module.exports = { shardSplitThreshold: argv.enableShardingExperiment ? argv.shardSplitThreshold : Infinity, 'cid-version': argv['cid-version'], 'raw-leaves': argv['raw-leaves'], - onlyHash: argv.onlyHash + onlyHash: argv['only-hash'] } // Temporary restriction on raw-leaves: diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 0cab4285ea..c14af03d36 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -147,7 +147,8 @@ exports.add = { is: 1, then: Joi.boolean().valid(false).required(), otherwise: Joi.boolean().valid(false) - }) + }), + 'only-hash': Joi.boolean() }) // TODO: Necessary until validate "recursive", "stream-channels" etc. .options({ allowUnknown: true }) @@ -205,10 +206,10 @@ exports.add = { const options = { 'cid-version': request.query['cid-version'], 'raw-leaves': request.query['raw-leaves'], - progress: request.query['progress'] ? progressHandler : null, - onlyHash: request.query['only-hash'] + progress: request.query.progress ? progressHandler : null, + onlyHash: !!request.query['only-hash'] } - console.log('http options:', options) + console.log('http add options:', options) const aborter = abortable() const stream = toStream.source(pull( diff --git a/test/cli/files.js b/test/cli/files.js index b2d317abd3..b1e8eee28a 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -270,6 +270,22 @@ describe('files', () => runOnAndOff((thing) => { }) }) + it('add --only-hash outputs correct hash', function () { + return ipfs('files add --only-hash src/init-files/init-docs/readme') + .then(out => + expect(out) + .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n') + ) + }) + + it('add --only-hash does not add the file to the datastore', function () { + return ipfs('files add --only-hash package.json') + .then(out => { + const speculativeHash = out.split(' ')[1] + return ipfs.fail(`files ls ${speculativeHash}`) + }) + }) + it('cat', function () { this.timeout(30 * 1000) diff --git a/test/http-api/extra/files.js b/test/http-api/extra/files.js new file mode 100644 index 0000000000..557e3f5ba1 --- /dev/null +++ b/test/http-api/extra/files.js @@ -0,0 +1,27 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + +module.exports = ctl => { + describe('.files', () => { + describe('.add', () => { + it.only('performs a speculative add, --only-hash', () => { + return ctl + .add(Buffer.from('finding dayz'), { onlyHash: true, progress: false }) + .then(result => { + console.log('result:', result) + return ctl.cat(result[0].hash).then(res => { + console.log('cat (shouldn\'t exist):', String(res)) + }) + }) + .catch(err => { + console.log('failed to add:', err) + }) + }) + }) + }) +} diff --git a/test/http-api/extra/version.js b/test/http-api/extra/version.js index 08552f0d3d..514f74d48b 100644 --- a/test/http-api/extra/version.js +++ b/test/http-api/extra/version.js @@ -6,17 +6,13 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -module.exports = (ctl) => { +module.exports = ctl => { describe('.version', () => { - it.only('gets the version', (done) => { - ctl.version((err, result) => { - console.log('Success! version results:', result) - expect(err).to.not.exist() + it('gets the version', () => + ctl.version().then(result => { expect(result).to.have.a.property('version') expect(result).to.have.a.property('commit') expect(result).to.have.a.property('repo') - done() - }) - }) + })) }) } From 7b14373615fe8e8004ac3be2c6185ba8afb4dafc Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 21 Feb 2018 19:21:02 -0500 Subject: [PATCH 06/10] update --only-hash test, increase timeout for the afterAll hook. I think it takes longer because the --only-hash test leaves an unresolved ipfs.ls command. Would love to be able to cancel it :) --- src/http/api/resources/files.js | 1 - test/http-api/extra/files.js | 23 ++++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index c14af03d36..64e27fc8a1 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -209,7 +209,6 @@ exports.add = { progress: request.query.progress ? progressHandler : null, onlyHash: !!request.query['only-hash'] } - console.log('http add options:', options) const aborter = abortable() const stream = toStream.source(pull( diff --git a/test/http-api/extra/files.js b/test/http-api/extra/files.js index 557e3f5ba1..2691be9959 100644 --- a/test/http-api/extra/files.js +++ b/test/http-api/extra/files.js @@ -6,20 +6,25 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +function resolveIn(ms) { + return new Promise(res => setTimeout(res, ms)) +} + module.exports = ctl => { describe('.files', () => { - describe('.add', () => { + describe('.add', function () { it.only('performs a speculative add, --only-hash', () => { return ctl - .add(Buffer.from('finding dayz'), { onlyHash: true, progress: false }) + .add(Buffer.from('Hola, Mundo'), { onlyHash: true }) .then(result => { - console.log('result:', result) - return ctl.cat(result[0].hash).then(res => { - console.log('cat (shouldn\'t exist):', String(res)) - }) - }) - .catch(err => { - console.log('failed to add:', err) + const lsAttempt = ctl.ls(result[0].hash) + .then(() => { + throw new Error('ls should not find a result for a file added with --only-hash') + }) + return Promise.race([ + lsAttempt, + new Promise(res => setTimeout(res, 4000)) + ]) }) }) }) From 233e0e29ce9798ebebb14808e027e085b9b15057 Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 22 Feb 2018 16:09:35 -0500 Subject: [PATCH 07/10] ipfs-exec/ipfs.fail should throw on a non-failing command && use random file for ipfs add --only-hash test. --- test/cli/files.js | 21 ++++++++++++++++----- test/http-api/extra/files.js | 19 +++++++++---------- test/utils/ipfs-exec.js | 14 +++++++++++--- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/test/cli/files.js b/test/cli/files.js index b1e8eee28a..e6185c9903 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -2,6 +2,7 @@ 'use strict' const fs = require('fs') +const os = require('os') const expect = require('chai').expect const path = require('path') const compareDir = require('dir-compare').compareSync @@ -278,11 +279,21 @@ describe('files', () => runOnAndOff((thing) => { ) }) - it('add --only-hash does not add the file to the datastore', function () { - return ipfs('files add --only-hash package.json') - .then(out => { - const speculativeHash = out.split(' ')[1] - return ipfs.fail(`files ls ${speculativeHash}`) + it('add --only-hash does not add a file to the datastore', function () { + this.timeout(30 * 1000) + this.slow(10 * 1000) + const content = String(Math.random() + Date.now()) + const filepath = path.join(os.tmpdir(), `${content}.txt`) + fs.writeFileSync(filepath, content) + + return ipfs(`files add --only-hash ${filepath}`) + .then(hash => { + const speculativeHash = hash.split(' ')[1] + return Promise.race([ + ipfs.fail(`object get ${speculativeHash}`), + new Promise(res => setTimeout(res, 5000)) + ]) + .then(() => fs.unlinkSync(filepath)) }) }) diff --git a/test/http-api/extra/files.js b/test/http-api/extra/files.js index 2691be9959..6571af62aa 100644 --- a/test/http-api/extra/files.js +++ b/test/http-api/extra/files.js @@ -6,23 +6,22 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -function resolveIn(ms) { - return new Promise(res => setTimeout(res, ms)) -} - module.exports = ctl => { describe('.files', () => { describe('.add', function () { - it.only('performs a speculative add, --only-hash', () => { + it('performs a speculative add, --only-hash', () => { + const content = String(Math.random() + Date.now()) + return ctl - .add(Buffer.from('Hola, Mundo'), { onlyHash: true }) - .then(result => { - const lsAttempt = ctl.ls(result[0].hash) + .add(Buffer.from(content), { onlyHash: true }) + .then(files => { + const getAttempt = ctl.object.get(files[0].hash) .then(() => { - throw new Error('ls should not find a result for a file added with --only-hash') + throw new Error('Should not find an object for content added with --only-hash') }) + return Promise.race([ - lsAttempt, + getAttempt, new Promise(res => setTimeout(res, 4000)) ]) }) diff --git a/test/utils/ipfs-exec.js b/test/utils/ipfs-exec.js index c9bcb53dc3..116d67c9b9 100644 --- a/test/utils/ipfs-exec.js +++ b/test/utils/ipfs-exec.js @@ -53,13 +53,21 @@ module.exports = (repoPath, opts) => { ipfs.fail = function ipfsFail () { let args = Array.from(arguments) + let caught = false if (args.length === 1) { args = args[0].split(' ') } - return exec(args).catch((err) => { - expect(err).to.exist() - }) + return exec(args) + .catch(err => { + caught = true + expect(err).to.exist() + }) + .then(() => { + if (!caught) { + throw new Error(`jsipfs expected to fail during command: jsipfs ${args.join(' ')}`) + } + }) } return ipfs From a1aa90a2d56e85a79f62be5fdceeed80678fe6b4 Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 22 Feb 2018 16:39:07 -0500 Subject: [PATCH 08/10] fix an ipfs config test. --- test/cli/config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/cli/config.js b/test/cli/config.js index 76d3c77f3d..2150c39e2c 100644 --- a/test/cli/config.js +++ b/test/cli/config.js @@ -68,7 +68,8 @@ describe('config', () => runOnAndOff((thing) => { }) it('call config with no arguments', () => { - return ipfs.fail('config') + return ipfs('config') + .then(out => expect(out).to.include('bin.js config [value]')) }) }) From 661c4bff9a9ac1cebfb3346e3d7c0738f8ef9aa9 Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 22 Feb 2018 16:48:10 -0500 Subject: [PATCH 09/10] lint --- src/cli/commands/files/add.js | 2 +- src/http/api/resources/files.js | 2 +- test/cli/files.js | 11 +++++++---- test/http-api/extra/files.js | 7 +++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index bcf43a554d..0dbdffe2c6 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -143,7 +143,7 @@ module.exports = { alias: 'n', type: 'boolean', default: false, - describe: 'Only chunk and hash, do not write to disk' + describe: 'Only chunk and hash, do not write' }, 'enable-sharding-experiment': { type: 'boolean', diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 64e27fc8a1..965c636f45 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -207,7 +207,7 @@ exports.add = { 'cid-version': request.query['cid-version'], 'raw-leaves': request.query['raw-leaves'], progress: request.query.progress ? progressHandler : null, - onlyHash: !!request.query['only-hash'] + onlyHash: Boolean(request.query['only-hash']) } const aborter = abortable() diff --git a/test/cli/files.js b/test/cli/files.js index e6185c9903..a034424647 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -287,11 +287,14 @@ describe('files', () => runOnAndOff((thing) => { fs.writeFileSync(filepath, content) return ipfs(`files add --only-hash ${filepath}`) - .then(hash => { - const speculativeHash = hash.split(' ')[1] + .then(out => { + const hash = out.split(' ')[1] + + // 'jsipfs object get ' should time out with the daemon on + // and should fail fast with the daemon off return Promise.race([ - ipfs.fail(`object get ${speculativeHash}`), - new Promise(res => setTimeout(res, 5000)) + ipfs.fail(`object get ${hash}`), + new Promise((resolve, reject) => setTimeout(resolve, 4000)) ]) .then(() => fs.unlinkSync(filepath)) }) diff --git a/test/http-api/extra/files.js b/test/http-api/extra/files.js index 6571af62aa..1e94114184 100644 --- a/test/http-api/extra/files.js +++ b/test/http-api/extra/files.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ +/* eslint max-nested-callbacks: ["error", 8] */ 'use strict' const chai = require('chai') const dirtyChai = require('dirty-chai') -const expect = chai.expect chai.use(dirtyChai) module.exports = ctl => { @@ -12,8 +12,7 @@ module.exports = ctl => { it('performs a speculative add, --only-hash', () => { const content = String(Math.random() + Date.now()) - return ctl - .add(Buffer.from(content), { onlyHash: true }) + return ctl.add(Buffer.from(content), { onlyHash: true }) .then(files => { const getAttempt = ctl.object.get(files[0].hash) .then(() => { @@ -22,7 +21,7 @@ module.exports = ctl => { return Promise.race([ getAttempt, - new Promise(res => setTimeout(res, 4000)) + new Promise((resolve, reject) => setTimeout(resolve, 4000)) ]) }) }) From f326ca922c31274fd7e0a92fc4a3642804a89497 Mon Sep 17 00:00:00 2001 From: jonkrone Date: Thu, 15 Mar 2018 15:30:53 -0400 Subject: [PATCH 10/10] clean: move test/http-api/extra/files.js to test/http-api/files.js --- test/cli/files.js | 2 +- test/http-api/extra/files.js | 30 ------------------------ test/http-api/extra/version.js | 18 --------------- test/http-api/files.js | 42 ++++++++++++++++++++++++++++++++++ test/utils/ipfs-exec.js | 5 ++++ 5 files changed, 48 insertions(+), 49 deletions(-) delete mode 100644 test/http-api/extra/files.js delete mode 100644 test/http-api/extra/version.js create mode 100644 test/http-api/files.js diff --git a/test/cli/files.js b/test/cli/files.js index a034424647..2e9fec39b5 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -290,7 +290,7 @@ describe('files', () => runOnAndOff((thing) => { .then(out => { const hash = out.split(' ')[1] - // 'jsipfs object get ' should time out with the daemon on + // 'jsipfs object get ' should timeout with the daemon on // and should fail fast with the daemon off return Promise.race([ ipfs.fail(`object get ${hash}`), diff --git a/test/http-api/extra/files.js b/test/http-api/extra/files.js deleted file mode 100644 index 1e94114184..0000000000 --- a/test/http-api/extra/files.js +++ /dev/null @@ -1,30 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -chai.use(dirtyChai) - -module.exports = ctl => { - describe('.files', () => { - describe('.add', function () { - it('performs a speculative add, --only-hash', () => { - const content = String(Math.random() + Date.now()) - - return ctl.add(Buffer.from(content), { onlyHash: true }) - .then(files => { - const getAttempt = ctl.object.get(files[0].hash) - .then(() => { - throw new Error('Should not find an object for content added with --only-hash') - }) - - return Promise.race([ - getAttempt, - new Promise((resolve, reject) => setTimeout(resolve, 4000)) - ]) - }) - }) - }) - }) -} diff --git a/test/http-api/extra/version.js b/test/http-api/extra/version.js deleted file mode 100644 index 514f74d48b..0000000000 --- a/test/http-api/extra/version.js +++ /dev/null @@ -1,18 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - -module.exports = ctl => { - describe('.version', () => { - it('gets the version', () => - ctl.version().then(result => { - expect(result).to.have.a.property('version') - expect(result).to.have.a.property('commit') - expect(result).to.have.a.property('repo') - })) - }) -} diff --git a/test/http-api/files.js b/test/http-api/files.js new file mode 100644 index 0000000000..4e2f297d70 --- /dev/null +++ b/test/http-api/files.js @@ -0,0 +1,42 @@ +/* eslint-env mocha */ +/* eslint max-nested-callbacks: ["error", 8] */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +chai.use(dirtyChai) + +describe('.files', () => { + 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('.add', function () { + it('performs a speculative add, --only-hash', () => { + const content = String(Math.random()) + + return ipfs.add(Buffer.from(content), { onlyHash: true }) + .then(files => { + const getAttempt = ipfs.object.get(files[0].hash) + .then(() => { + throw new Error('Should not find an object for content added with --only-hash') + }) + + return Promise.race([ + getAttempt, + new Promise((resolve, reject) => setTimeout(resolve, 4000)) + ]) + }) + }) + }) +}) diff --git a/test/utils/ipfs-exec.js b/test/utils/ipfs-exec.js index 116d67c9b9..2437f136a9 100644 --- a/test/utils/ipfs-exec.js +++ b/test/utils/ipfs-exec.js @@ -51,6 +51,11 @@ module.exports = (repoPath, opts) => { return res } + /** + * Expect the command passed as @param arguments to fail. + * @return {Promise} Resolves if the command passed as @param arguments fails, + * rejects if it was successful. + */ ipfs.fail = function ipfsFail () { let args = Array.from(arguments) let caught = false