From a58ac3cff5f65c0448eb1ef8eb3b13c53c3a037f Mon Sep 17 00:00:00 2001 From: Stephen Whitmore Date: Thu, 23 Jun 2016 12:18:49 -0700 Subject: [PATCH] Check directory contents in "get" test. --- src/files.js | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/files.js b/src/files.js index 07e08226..bf78c2c2 100644 --- a/src/files.js +++ b/src/files.js @@ -11,7 +11,7 @@ const concat = require('concat-stream') const through = require('through2') module.exports = (common) => { - describe.only('.files', () => { + describe('.files', () => { let smallFile let bigFile let directoryContent @@ -185,7 +185,7 @@ module.exports = (common) => { const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' ipfs.cat(hash, (err, stream) => { expect(err).to.not.exist - stream.pipe(bl((err, data) => { + stream.pipe(concat((data) => { expect(err).to.not.exist expect(data.toString()).to.contain('Check out some of the other files in this directory:') done() @@ -197,21 +197,23 @@ module.exports = (common) => { const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' ipfs.cat(hash, (err, stream) => { expect(err).to.not.exist - stream.pipe(bl((err, data) => { + stream.pipe(concat((data) => { expect(err).to.not.exist expect(data).to.deep.equal(bigFile) done() })) }) + }) - it('with a multihash', (done) => { - const mhBuf = new Buffer(bs58.decode('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')) - ipfs.cat(mhBuf, (err, stream) => { - expect(err).to.not.exist - stream.pipe(concat((data) => { - expect(data.toString()).to.contain('Check out some of the other files in this directory:') - done() - })) + it('with a multihash', (done) => { + const mhBuf = new Buffer(bs58.decode('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')) + ipfs.cat(mhBuf, (err, stream) => { + expect(err).to.not.exist + stream.pipe(concat((data) => { + expect(data.toString()).to.contain('Check out some of the other files in this directory:') + done() + })) + }) }) }) }) @@ -306,7 +308,7 @@ module.exports = (common) => { expect(err).to.not.exist stream.pipe(concat((files) => { expect(files).to.be.length(1) - expect(files[0].path).to.deep.equal(hash) + expect(files[0].path).to.deep.equal(mhBuf) files[0].content.pipe(concat((content) => { expect(content.toString()).to.contain('Check out some of the other files in this directory:') done() @@ -360,6 +362,7 @@ module.exports = (common) => { next() } }, () => { + // Check paths var paths = files.map((file) => { return file.path }) @@ -375,6 +378,23 @@ module.exports = (common) => { 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt', 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt', ]) + + // Check contents + var contents = files.map((file) => { + return file.content ? file.content : null + }) + expect(contents).to.deep.equal([ + null, + directoryContent['alice.txt'], + null, + null, + null, + directoryContent['files/hello.txt'], + directoryContent['files/ipfs.txt'], + directoryContent['holmes.txt'], + directoryContent['jungle.txt'], + directoryContent['pp.txt'], + ]) done() })) })