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

Commit

Permalink
Check directory contents in "get" test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed Jul 14, 2016
1 parent 46fa99a commit a58ac3c
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
}))
})
})
})
})
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -360,6 +362,7 @@ module.exports = (common) => {
next()
}
}, () => {
// Check paths
var paths = files.map((file) => {
return file.path
})
Expand All @@ -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()
}))
})
Expand Down

0 comments on commit a58ac3c

Please sign in to comment.