Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

test: fix resolve test #385

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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