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

Commit 61cc277

Browse files
committed
Merge pull request #27 from ipfs/feature/createAddStream
add createAddStream tests
2 parents de2f861 + 317e605 commit 61cc277

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/files.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,54 @@ module.exports = (common) => {
133133
})
134134
})
135135

136+
it('createAddStream', (done) => {
137+
if (!isNode) {
138+
return done()
139+
// can't run this test cause browserify
140+
// can't shim readFileSync in runtime
141+
}
142+
143+
const base = path.join(__dirname, 'data/test-folder')
144+
const content = (name) => ({
145+
path: `test-folder/${name}`,
146+
content: fs.readFileSync(path.join(base, name))
147+
})
148+
const emptyDir = (name) => ({
149+
path: `test-folder/${name}`
150+
})
151+
152+
const files = [
153+
content('pp.txt'),
154+
content('holmes.txt'),
155+
content('jungle.txt'),
156+
content('alice.txt'),
157+
emptyDir('empty-folder'),
158+
content('files/hello.txt'),
159+
content('files/ipfs.txt'),
160+
emptyDir('files/empty')
161+
]
162+
163+
ipfs.files.createAddStream((err, stream) => {
164+
expect(err).to.not.exist
165+
166+
stream.on('data', (tuple) => {
167+
if (tuple.path === 'test-folder') {
168+
const mh = bs58.encode(tuple.node.multihash()).toString()
169+
expect(mh).to.equal('QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP')
170+
expect(tuple.node.links).to.have.length(6)
171+
}
172+
})
173+
174+
stream.on('end', done)
175+
176+
files.forEach((file) => {
177+
stream.write(file)
178+
})
179+
180+
stream.end()
181+
})
182+
})
183+
136184
describe('promise', () => {
137185
it('buffer', () => {
138186
return ipfs.files.add(smallFile)

0 commit comments

Comments
 (0)