This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add onlyHash option to files.add (#259)
- Loading branch information
Showing
3 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ const path = require('path') | |
const bl = require('bl') | ||
const isNode = require('detect-node') | ||
const CID = require('cids') | ||
const expectTimeout = require('./utils/expect-timeout') | ||
|
||
module.exports = (common) => { | ||
describe('.files', function () { | ||
|
@@ -334,6 +335,19 @@ module.exports = (common) => { | |
expect(file.path).to.equal(smallFile.cid) | ||
}) | ||
}) | ||
|
||
it('files.add with only-hash=true', () => { | ||
this.slow(10 * 1000) | ||
const content = String(Math.random() + Date.now()) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
return ipfs.files.add(Buffer.from(content), { onlyHash: true }) | ||
.then(files => { | ||
expect(files).to.have.length(1) | ||
This comment has been minimized.
Sorry, something went wrong.
victorb
Contributor
|
||
|
||
// 'ipfs.object.get(<hash>)' should timeout because content wasn't actually added | ||
return expectTimeout(ipfs.object.get(files[0].hash), 4000) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('.addReadableStream', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict' | ||
|
||
/** | ||
* Resolve if @param promise hangs for at least @param ms, throw otherwise | ||
* @param {Promise} promise promise that you expect to hang | ||
* @param {Number} ms millis to wait | ||
* @return {Promise} | ||
*/ | ||
module.exports = (promise, ms) => { | ||
return Promise.race([ | ||
promise.then((out) => { | ||
throw new Error('Expected Promise to timeout but it was successful.') | ||
}), | ||
new Promise((resolve, reject) => setTimeout(resolve, ms)) | ||
]) | ||
} |
Tests should generally not have any random data inside them as they should be predicable