Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: supported add inputs (#519)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Alan Shaw authored Sep 3, 2019
1 parent cdb6b36 commit ddc4fe7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/dht/provide.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
14 changes: 10 additions & 4 deletions src/files-regular/add-from-stream.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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()
})
})
Expand Down
42 changes: 22 additions & 20 deletions src/files-regular/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -154,31 +153,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()
})
})
Expand Down Expand Up @@ -353,7 +355,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()
Expand Down

0 comments on commit ddc4fe7

Please sign in to comment.