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

add createAddStream tests #27

Merged
merged 1 commit into from
Jun 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,54 @@ module.exports = (common) => {
})
})

it('createAddStream', (done) => {
if (!isNode) {
return done()
// can't run this test cause browserify
// can't shim readFileSync in runtime
}

const base = path.join(__dirname, 'data/test-folder')
const content = (name) => ({
path: `test-folder/${name}`,
content: fs.readFileSync(path.join(base, name))
})
const emptyDir = (name) => ({
path: `test-folder/${name}`
})

const files = [
content('pp.txt'),
content('holmes.txt'),
content('jungle.txt'),
content('alice.txt'),
emptyDir('empty-folder'),
content('files/hello.txt'),
content('files/ipfs.txt'),
emptyDir('files/empty')
]

ipfs.files.createAddStream((err, stream) => {
expect(err).to.not.exist

stream.on('data', (tuple) => {
if (tuple.path === 'test-folder') {
const mh = bs58.encode(tuple.node.multihash()).toString()
expect(mh).to.equal('QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP')
expect(tuple.node.links).to.have.length(6)
}
})

stream.on('end', done)

files.forEach((file) => {
stream.write(file)
})

stream.end()
})
})

describe('promise', () => {
it('buffer', () => {
return ipfs.files.add(smallFile)
Expand Down