Skip to content

Commit

Permalink
test: fix resolve test (ipfs#385)
Browse files Browse the repository at this point in the history
* 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 <alan.shaw@protocol.ai>
  • Loading branch information
Stebalien authored and Alan Shaw committed Feb 19, 2019
1 parent b674158 commit 92fb51b
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/miscellaneous/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down

0 comments on commit 92fb51b

Please sign in to comment.