From 54beacb152ff2207a152cb5d579859221b83b564 Mon Sep 17 00:00:00 2001 From: Zane Starr Date: Thu, 26 Apr 2018 19:55:39 -0700 Subject: [PATCH] Add explicit test for resolver.getPullStream --- src/index.js | 2 +- test/ipld-all.js | 13 ++++++++++++- test/ipld-dag-cbor.js | 14 -------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/index.js b/src/index.js index e3e76a5..7ee3db0 100644 --- a/src/index.js +++ b/src/index.js @@ -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 }) } diff --git a/test/ipld-all.js b/test/ipld-all.js index 8a7cecf..0b043e5 100644 --- a/test/ipld-all.js +++ b/test/ipld-all.js @@ -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') @@ -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() @@ -77,5 +89,4 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => { done() }) }) - }) diff --git a/test/ipld-dag-cbor.js b/test/ipld-dag-cbor.js index 19ab1b5..88681dd 100644 --- a/test/ipld-dag-cbor.js +++ b/test/ipld-dag-cbor.js @@ -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)