From b3e94eb1f5f5a4e2bf8d22417bf64b89c6b23b60 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 3 Sep 2019 14:07:00 +0100 Subject: [PATCH 1/5] fix: supported add inputs This PR updates the tests with new supported inputs for add. refs https://github.com/ipfs/js-ipfs-http-client/pull/1087 License: MIT Signed-off-by: Alan Shaw --- package.json | 1 - src/dht/provide.js | 5 +++- src/files-regular/add-from-stream.js | 14 +++++++--- src/files-regular/add.js | 41 +++++++++++++++------------- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index d3d302c37..9fd19be98 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "dirty-chai": "^2.0.1", "es6-promisify": "^6.0.1", "hat": "0.0.3", - "into-stream": "^5.1.0", "ipfs-block": "~0.8.0", "ipfs-unixfs": "~0.1.16", "ipfs-utils": "~0.0.3", diff --git a/src/dht/provide.js b/src/dht/provide.js index 915f9f266..11fbe88f0 100644 --- a/src/dht/provide.js +++ b/src/dht/provide.js @@ -60,7 +60,10 @@ module.exports = (createCommon, options) => { }) it('should allow multiple CIDs to be passed', (done) => { - ipfs.add([Buffer.from('t0'), Buffer.from('t1')], (err, res) => { + ipfs.add([ + { content: Buffer.from('t0') }, + { content: Buffer.from('t1') } + ], (err, res) => { if (err) return done(err) ipfs.dht.provide([ diff --git a/src/files-regular/add-from-stream.js b/src/files-regular/add-from-stream.js index f97a5946e..96ae0938d 100644 --- a/src/files-regular/add-from-stream.js +++ b/src/files-regular/add-from-stream.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ 'use strict' -const loadFixture = require('aegir/fixtures') -const into = require('into-stream') +const { Readable } = require('readable-stream') const { getDescribe, getIt, expect } = require('../utils/mocha') +const { fixtures } = require('./utils') module.exports = (createCommon, options) => { const describe = getDescribe(options) @@ -33,11 +33,17 @@ module.exports = (createCommon, options) => { after((done) => common.teardown(done)) it('should add from a stream', (done) => { - const testData = loadFixture('test/fixtures/15mb.random', 'interface-ipfs-core') + const stream = new Readable({ + read () { + this.push(fixtures.bigFile.data) + this.push(null) + } + }) - ipfs.addFromStream(into(testData), (err, result) => { + ipfs.addFromStream(stream, (err, result) => { expect(err).to.not.exist() expect(result.length).to.equal(1) + expect(result[0].hash).to.equal(fixtures.bigFile.cid) done() }) }) diff --git a/src/files-regular/add.js b/src/files-regular/add.js index eb364306d..bc12c6b84 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -154,31 +154,34 @@ module.exports = (createCommon, options) => { }) }) - it('should not be able to add by path', (done) => { - const validPath = path.join(process.cwd() + '/package.json') + it('should add a string', (done) => { + const data = 'a string' + const expectedCid = 'QmQFRCwEpwQZ5aQMqCsCaFbdjNLLHoyZYDjr92v1F7HeqX' - ipfs.add(validPath, (err, res) => { - expect(err).to.exist() - done() - }) - }) - - it('should not be able to add a string', (done) => { - const data = `TEST${Date.now()}` + ipfs.add(data, (err, filesAdded) => { + expect(err).to.not.exist() - ipfs.add(data, (err) => { - expect(err).to.exist() - expect(err.message).to.contain('Input not supported') + expect(filesAdded).to.be.length(1) + const { path, size, hash } = filesAdded[0] + expect(path).to.equal(expectedCid) + expect(size).to.equal(16) + expect(hash).to.equal(expectedCid) done() }) }) - it('should not be able to add a non-Buffer TypedArray', (done) => { - const data = Uint8Array.from([Date.now()]) + it('should add a TypedArray', (done) => { + const data = Uint8Array.from([1, 3, 8]) + const expectedCid = 'QmRyUEkVCuHC8eKNNJS9BDM9jqorUvnQJK1DM81hfngFqd' - ipfs.add(data, (err) => { - expect(err).to.exist() - expect(err.message).to.contain('Input not supported') + ipfs.add(data, (err, filesAdded) => { + expect(err).to.not.exist() + + expect(filesAdded).to.be.length(1) + const { path, size, hash } = filesAdded[0] + expect(path).to.equal(expectedCid) + expect(size).to.equal(11) + expect(hash).to.equal(expectedCid) done() }) }) @@ -353,7 +356,7 @@ module.exports = (createCommon, options) => { }) it('should fail when passed invalid input', (done) => { - const nonValid = 'sfdasfasfs' + const nonValid = 138 ipfs.add(nonValid, (err, result) => { expect(err).to.exist() From b0c999aa610ef63244661f254adcb45d93febad5 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 3 Sep 2019 15:39:32 +0100 Subject: [PATCH 2/5] fix: test for hidden file - only 10 items License: MIT Signed-off-by: Alan Shaw --- src/files-regular/add-from-fs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files-regular/add-from-fs.js b/src/files-regular/add-from-fs.js index b2f35cfa9..2c012f5ba 100644 --- a/src/files-regular/add-from-fs.js +++ b/src/files-regular/add-from-fs.js @@ -76,7 +76,7 @@ module.exports = (createCommon, options) => { const filesPath = path.join(fixturesPath, 'hidden-files-folder') ipfs.addFromFs(filesPath, { recursive: true, hidden: true }, (err, result) => { expect(err).to.not.exist() - expect(result.length).to.be.above(10) + expect(result.length).to.be(10) expect(result.map(object => object.path)).to.include('hidden-files-folder/.hiddenTest.txt') expect(result.map(object => object.hash)).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt') done() From 0541756a74064511a2ce2b6da4d75e7c620a43e9 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 3 Sep 2019 15:41:34 +0100 Subject: [PATCH 3/5] fix: test assertion License: MIT Signed-off-by: Alan Shaw --- src/files-regular/add-from-fs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files-regular/add-from-fs.js b/src/files-regular/add-from-fs.js index 2c012f5ba..77b551436 100644 --- a/src/files-regular/add-from-fs.js +++ b/src/files-regular/add-from-fs.js @@ -76,7 +76,7 @@ module.exports = (createCommon, options) => { const filesPath = path.join(fixturesPath, 'hidden-files-folder') ipfs.addFromFs(filesPath, { recursive: true, hidden: true }, (err, result) => { expect(err).to.not.exist() - expect(result.length).to.be(10) + expect(result.length).to.equal(10) expect(result.map(object => object.path)).to.include('hidden-files-folder/.hiddenTest.txt') expect(result.map(object => object.hash)).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt') done() From 48eccbbde23e8ec7753318e5defc8f5c387c0e92 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 3 Sep 2019 15:43:35 +0100 Subject: [PATCH 4/5] chore: appease linter License: MIT Signed-off-by: Alan Shaw --- src/files-regular/add.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/files-regular/add.js b/src/files-regular/add.js index bc12c6b84..4d3c34d9d 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -4,7 +4,6 @@ const { fixtures } = require('./utils') const Readable = require('readable-stream').Readable const pull = require('pull-stream') -const path = require('path') const expectTimeout = require('../utils/expect-timeout') const { getDescribe, getIt, expect } = require('../utils/mocha') const { supportsFileReader } = require('ipfs-utils/src/supports') From 27d688038a01cbcd624ee2d2a4c5acfffeead48e Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 3 Sep 2019 15:52:25 +0100 Subject: [PATCH 5/5] fix: test License: MIT Signed-off-by: Alan Shaw --- src/files-regular/add-from-fs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files-regular/add-from-fs.js b/src/files-regular/add-from-fs.js index 77b551436..b2f35cfa9 100644 --- a/src/files-regular/add-from-fs.js +++ b/src/files-regular/add-from-fs.js @@ -76,7 +76,7 @@ module.exports = (createCommon, options) => { const filesPath = path.join(fixturesPath, 'hidden-files-folder') ipfs.addFromFs(filesPath, { recursive: true, hidden: true }, (err, result) => { expect(err).to.not.exist() - expect(result.length).to.equal(10) + expect(result.length).to.be.above(10) expect(result.map(object => object.path)).to.include('hidden-files-folder/.hiddenTest.txt') expect(result.map(object => object.hash)).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt') done()