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

Commit cb32493

Browse files
committed
Add ipfs.files.test for a directory.
1 parent 16a006f commit cb32493

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

src/files.js

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ const path = require('path')
88
const fs = require('fs')
99
const isNode = require('detect-node')
1010
const concat = require('concat-stream')
11+
const through = require('through2')
1112

1213
module.exports = (common) => {
13-
describe.only('.files', () => {
14+
describe('.files', () => {
1415
let smallFile
1516
let bigFile
1617
let ipfs
@@ -313,7 +314,7 @@ module.exports = (common) => {
313314
expect(err).to.not.exist
314315
stream.pipe(concat((files) => {
315316
expect(files).to.be.length(1)
316-
expect(files[0].path).to.deep.equal(mhBuf)
317+
expect(files[0].path).to.deep.equal(hash)
317318
files[0].content.pipe(concat((content) => {
318319
expect(content.toString()).to.contain('Check out some of the other files in this directory:')
319320
done()
@@ -326,13 +327,59 @@ module.exports = (common) => {
326327
const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
327328
ipfs.files.get(hash, (err, stream) => {
328329
expect(err).to.not.exist
329-
stream.pipe(concat((files) => {
330-
expect(files).to.be.length(1)
330+
331+
// accumulate the files and their content
332+
var files = []
333+
stream.pipe(through.obj((file, enc, next) => {
334+
file.content.pipe(concat((content) => {
335+
files.push({
336+
path: file.path,
337+
content: content
338+
})
339+
next()
340+
}))
341+
}, () => {
342+
expect(files.length).to.equal(1)
331343
expect(files[0].path).to.equal(hash)
332-
files[0].content.pipe(concat((content) => {
333-
expect(content).to.deep.equal(bigFile)
334-
done()
344+
expect(files[0].content).to.deep.equal(bigFile)
345+
done()
346+
}))
347+
})
348+
})
349+
350+
it('directory', (done) => {
351+
const hash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
352+
ipfs.files.get(hash, (err, stream) => {
353+
expect(err).to.not.exist
354+
355+
// accumulate the files and their content
356+
var files = []
357+
stream.pipe(through.obj((file, enc, next) => {
358+
file.content.pipe(concat((content) => {
359+
files.push({
360+
path: file.path,
361+
content: content
362+
})
363+
next()
335364
}))
365+
}, () => {
366+
expect(files).to.be.length(10)
367+
var paths = files.map((file) => {
368+
return file.path
369+
})
370+
expect(paths).to.deep.equal([
371+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP',
372+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt',
373+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder',
374+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files',
375+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/empty',
376+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/hello.txt',
377+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files/ipfs.txt',
378+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt',
379+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt',
380+
'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt',
381+
])
382+
done()
336383
}))
337384
})
338385
})

0 commit comments

Comments
 (0)