Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Add explicit test for resolver.getPullStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Starr committed Apr 27, 2018
1 parent 1dce3d5 commit 54beacb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class IPLDResolver {
const endReached = !path || path === '' || path === '/'
const isTerminal = value && !value['/']

if ((endReached && isTerminal) || options.localResolve) {
if ((endReached && isTerminal) || (options && options.localResolve)) {
stop = true
return cb(null, { value, remainderPath: path })
}
Expand Down
13 changes: 12 additions & 1 deletion test/ipld-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const dagPB = require('ipld-dag-pb')
const dagCBOR = require('ipld-dag-cbor')
const each = require('async/each')
const waterfall = require('async/waterfall')
const pull = require('pull-stream')

const IPLDResolver = require('../src')

Expand Down Expand Up @@ -69,6 +70,17 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => {
})
})

it('resolver.getPullStream through different formats', (done) => {
pull(resolver.getPullStream(cidCbor, 'pb/Data'),
pull.collect((err, results) => {
expect(err).to.not.exist()
expect(results.length).to.eq(2)
dagCBOR.util.cid(results[0].value['/'], (cid) => expect(cid).to.eql(cidPb))
expect(results[1].value).to.eql(Buffer.from('I am inside a Protobuf'))
done()
}))
})

it('resolve honors onlyNode option', (done) => {
resolver.get(cidCbor, 'pb/Data', { onlyNode: true }, (err, result) => {
expect(err).to.not.exist()
Expand All @@ -77,5 +89,4 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => {
done()
})
})

})
14 changes: 0 additions & 14 deletions test/ipld-dag-cbor.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,6 @@ module.exports = (repo) => {
}, done)
})

it('resolver.getPullStream just CID', (done) => {
pull(resolver.getPullStream(cid1, null),
pull.collect((err, results) => {
expect(err).to.not.exist()
expect(results.length).to.eq(1)

dagCBOR.util.cid(results[0].value, (err, cid) => {
expect(err).to.not.exist()
expect(cid).to.eql(cid1)
})
}))
done()
})

it('resolver.get just CID', (done) => {
resolver.get(cid1, (err, results) => {
expect(results.length).to.eq(1)
Expand Down

0 comments on commit 54beacb

Please sign in to comment.