Skip to content

Commit ddc4fe7

Browse files
author
Alan Shaw
authored
fix: supported add inputs (ipfs#519)
* fix: supported add inputs This PR updates the tests with new supported inputs for add. refs ipfs-inactive/js-ipfs-http-client#1087 License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai> * fix: test for hidden file - only 10 items License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai> * fix: test assertion License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai> * chore: appease linter License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai> * fix: test License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent cdb6b36 commit ddc4fe7

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"dirty-chai": "^2.0.1",
4646
"es6-promisify": "^6.0.1",
4747
"hat": "0.0.3",
48-
"into-stream": "^5.1.0",
4948
"ipfs-block": "~0.8.0",
5049
"ipfs-unixfs": "~0.1.16",
5150
"ipfs-utils": "~0.0.3",

src/dht/provide.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ module.exports = (createCommon, options) => {
6060
})
6161

6262
it('should allow multiple CIDs to be passed', (done) => {
63-
ipfs.add([Buffer.from('t0'), Buffer.from('t1')], (err, res) => {
63+
ipfs.add([
64+
{ content: Buffer.from('t0') },
65+
{ content: Buffer.from('t1') }
66+
], (err, res) => {
6467
if (err) return done(err)
6568

6669
ipfs.dht.provide([

src/files-regular/add-from-stream.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const loadFixture = require('aegir/fixtures')
5-
const into = require('into-stream')
4+
const { Readable } = require('readable-stream')
65
const { getDescribe, getIt, expect } = require('../utils/mocha')
6+
const { fixtures } = require('./utils')
77

88
module.exports = (createCommon, options) => {
99
const describe = getDescribe(options)
@@ -33,11 +33,17 @@ module.exports = (createCommon, options) => {
3333
after((done) => common.teardown(done))
3434

3535
it('should add from a stream', (done) => {
36-
const testData = loadFixture('test/fixtures/15mb.random', 'interface-ipfs-core')
36+
const stream = new Readable({
37+
read () {
38+
this.push(fixtures.bigFile.data)
39+
this.push(null)
40+
}
41+
})
3742

38-
ipfs.addFromStream(into(testData), (err, result) => {
43+
ipfs.addFromStream(stream, (err, result) => {
3944
expect(err).to.not.exist()
4045
expect(result.length).to.equal(1)
46+
expect(result[0].hash).to.equal(fixtures.bigFile.cid)
4147
done()
4248
})
4349
})

src/files-regular/add.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const { fixtures } = require('./utils')
55
const Readable = require('readable-stream').Readable
66
const pull = require('pull-stream')
7-
const path = require('path')
87
const expectTimeout = require('../utils/expect-timeout')
98
const { getDescribe, getIt, expect } = require('../utils/mocha')
109
const { supportsFileReader } = require('ipfs-utils/src/supports')
@@ -154,31 +153,34 @@ module.exports = (createCommon, options) => {
154153
})
155154
})
156155

157-
it('should not be able to add by path', (done) => {
158-
const validPath = path.join(process.cwd() + '/package.json')
156+
it('should add a string', (done) => {
157+
const data = 'a string'
158+
const expectedCid = 'QmQFRCwEpwQZ5aQMqCsCaFbdjNLLHoyZYDjr92v1F7HeqX'
159159

160-
ipfs.add(validPath, (err, res) => {
161-
expect(err).to.exist()
162-
done()
163-
})
164-
})
165-
166-
it('should not be able to add a string', (done) => {
167-
const data = `TEST${Date.now()}`
160+
ipfs.add(data, (err, filesAdded) => {
161+
expect(err).to.not.exist()
168162

169-
ipfs.add(data, (err) => {
170-
expect(err).to.exist()
171-
expect(err.message).to.contain('Input not supported')
163+
expect(filesAdded).to.be.length(1)
164+
const { path, size, hash } = filesAdded[0]
165+
expect(path).to.equal(expectedCid)
166+
expect(size).to.equal(16)
167+
expect(hash).to.equal(expectedCid)
172168
done()
173169
})
174170
})
175171

176-
it('should not be able to add a non-Buffer TypedArray', (done) => {
177-
const data = Uint8Array.from([Date.now()])
172+
it('should add a TypedArray', (done) => {
173+
const data = Uint8Array.from([1, 3, 8])
174+
const expectedCid = 'QmRyUEkVCuHC8eKNNJS9BDM9jqorUvnQJK1DM81hfngFqd'
178175

179-
ipfs.add(data, (err) => {
180-
expect(err).to.exist()
181-
expect(err.message).to.contain('Input not supported')
176+
ipfs.add(data, (err, filesAdded) => {
177+
expect(err).to.not.exist()
178+
179+
expect(filesAdded).to.be.length(1)
180+
const { path, size, hash } = filesAdded[0]
181+
expect(path).to.equal(expectedCid)
182+
expect(size).to.equal(11)
183+
expect(hash).to.equal(expectedCid)
182184
done()
183185
})
184186
})
@@ -353,7 +355,7 @@ module.exports = (createCommon, options) => {
353355
})
354356

355357
it('should fail when passed invalid input', (done) => {
356-
const nonValid = 'sfdasfasfs'
358+
const nonValid = 138
357359

358360
ipfs.add(nonValid, (err, result) => {
359361
expect(err).to.exist()

0 commit comments

Comments
 (0)