From 1021c75d5b3ebec216c2b23ce77ca631b4167037 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 30 Oct 2018 10:01:14 -0700 Subject: [PATCH 1/2] test: fix resolve test 1. This is an IPLD path. 2. Resolve really should be resolving up to the last path, not just "failing". --- src/miscellaneous/resolve.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/miscellaneous/resolve.js b/src/miscellaneous/resolve.js index 50864bae6..548555ddd 100644 --- a/src/miscellaneous/resolve.js +++ b/src/miscellaneous/resolve.js @@ -88,17 +88,17 @@ 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 = `/ipld/${cid.toBaseEncodedString()}/path/to/file` + ipfs.resolve(path, (err, resolved) => { + expect(err).to.not.exist() + expect(resolved).to.be(path) done() }) }) From 457787c82c96e212ab6026c416d5a66bf336b1e9 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 19 Feb 2019 12:35:00 +0000 Subject: [PATCH 2/2] fix: resolve test and add resolve across multiple test License: MIT Signed-off-by: Alan Shaw --- src/miscellaneous/resolve.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/miscellaneous/resolve.js b/src/miscellaneous/resolve.js index 548555ddd..e613ef072 100644 --- a/src/miscellaneous/resolve.js +++ b/src/miscellaneous/resolve.js @@ -95,10 +95,34 @@ module.exports = (createCommon, options) => { ipfs.dag.put(content, options, (err, cid) => { expect(err).to.not.exist() - const path = `/ipld/${cid.toBaseEncodedString()}/path/to/file` + const path = `/ipfs/${cid}/path/to/file` ipfs.resolve(path, (err, resolved) => { expect(err).to.not.exist() - expect(resolved).to.be(path) + 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() }) })