From 92fb51b77ee443a4146eb831ebb91a9d168ebd28 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 19 Feb 2019 05:16:47 -0800 Subject: [PATCH] test: fix resolve test (#385) * test: fix resolve test 1. This is an IPLD path. 2. Resolve really should be resolving up to the last path, not just "failing". * fix: resolve test and add resolve across multiple test License: MIT Signed-off-by: Alan Shaw --- src/miscellaneous/resolve.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/miscellaneous/resolve.js b/src/miscellaneous/resolve.js index 50864bae6d..e613ef0726 100644 --- a/src/miscellaneous/resolve.js +++ b/src/miscellaneous/resolve.js @@ -88,17 +88,41 @@ module.exports = (createCommon, options) => { }) }) - it('should not resolve an IPFS path non-link', (done) => { + it('should resolve up to the last node', (done) => { const content = { path: { to: { file: hat() } } } const options = { format: 'dag-cbor', hashAlg: 'sha2-256' } ipfs.dag.put(content, options, (err, cid) => { expect(err).to.not.exist() - const path = `/ipfs/${cid.toBaseEncodedString()}/path/to/file` - ipfs.resolve(path, (err, path) => { - expect(err).to.exist() - expect(err.message).to.equal('found non-link at given path') + const path = `/ipfs/${cid}/path/to/file` + ipfs.resolve(path, (err, resolved) => { + expect(err).to.not.exist() + expect(resolved).to.equal(path) + done() + }) + }) + }) + + it('should resolve up to the last node across multiple nodes', (done) => { + const options = { format: 'dag-cbor', hashAlg: 'sha2-256' } + + waterfall([ + cb => { + const content = { node: { with: { file: hat() } } } + ipfs.dag.put(content, options, cb) + }, + (childCid, cb) => { + const content = { path: { to: childCid } } + ipfs.dag.put(content, options, (err, parentCid) => cb(err, { childCid, parentCid })) + } + ], (err, res) => { + expect(err).to.not.exist() + + const path = `/ipfs/${res.parentCid}/path/to/node/with/file` + ipfs.resolve(path, (err, resolved) => { + expect(err).to.not.exist() + expect(resolved).to.equal(`/ipfs/${res.childCid}/node/with/file`) done() }) })