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

Commit 1c853a1

Browse files
author
Alan Shaw
committed
test: add test for add files to dir non sequentially
Output is: ```js [ { path: 'test-dir/b/jungle.txt', hash: 'QmT6orWioMiSqXXPGsUi71CKRRUmJ8YkuueV2DPV34E9y9', size: 2305 }, { path: 'test-dir/b', hash: 'QmfQm3xnDNKHRxPxb3z1UA81Cst8wWdA93dZC6oPRbTWHm', size: 2362 }, { path: 'test-dir/a/pp.txt', hash: 'QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn', size: 4551 }, { path: 'test-dir/a/holmes.txt', hash: 'QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr', size: 582072 }, { path: 'test-dir/a/alice.txt', hash: 'QmZyUEQVuRK3XV7L9Dk26pg6RVSgaYkiSTEdnT2kZZdwoi', size: 11696 }, { path: 'test-dir/a', hash: 'QmXh4P8PwnYDrN62u1GRunyhoEnW68vTR7TXkBxodkxsmw', size: 598478 }, { path: 'test-dir', hash: 'QmVBueuZRsuNgvExGFyTUGcLs2pdUMaKWrXu5fY37BaT2T', size: 600933 } ] ``` License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 4fdb6f6 commit 1c853a1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/files-regular/add.js

+27
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,33 @@ module.exports = (createCommon, options) => {
325325
})
326326
})
327327

328+
it('should add files to a directory non sequentially', function (done) {
329+
const content = path => ({
330+
path: `test-dir/${path}`,
331+
content: fixtures.directory.files[path.split('/').pop()]
332+
})
333+
334+
const input = [
335+
content('a/pp.txt'),
336+
content('a/holmes.txt'),
337+
content('b/jungle.txt'),
338+
content('a/alice.txt')
339+
]
340+
341+
ipfs.add(input, (err, filesAdded) => {
342+
expect(err).to.not.exist()
343+
344+
const toPath = ({ path }) => path
345+
const nonSeqDirFilePaths = input.map(toPath).filter(p => p.includes('/a/'))
346+
const filesAddedPaths = filesAdded.map(toPath)
347+
348+
expect(nonSeqDirFilePaths.every(p => filesAddedPaths.includes(p)))
349+
.to.be.true()
350+
351+
done()
352+
})
353+
})
354+
328355
it('should fail when passed invalid input', (done) => {
329356
const nonValid = 'sfdasfasfs'
330357

0 commit comments

Comments
 (0)