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

Commit 92fb51b

Browse files
StebalienAlan Shaw
authored and
Alan Shaw
committed
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 <alan.shaw@protocol.ai>
1 parent b674158 commit 92fb51b

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/miscellaneous/resolve.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,41 @@ module.exports = (createCommon, options) => {
8888
})
8989
})
9090

91-
it('should not resolve an IPFS path non-link', (done) => {
91+
it('should resolve up to the last node', (done) => {
9292
const content = { path: { to: { file: hat() } } }
9393
const options = { format: 'dag-cbor', hashAlg: 'sha2-256' }
9494

9595
ipfs.dag.put(content, options, (err, cid) => {
9696
expect(err).to.not.exist()
9797

98-
const path = `/ipfs/${cid.toBaseEncodedString()}/path/to/file`
99-
ipfs.resolve(path, (err, path) => {
100-
expect(err).to.exist()
101-
expect(err.message).to.equal('found non-link at given path')
98+
const path = `/ipfs/${cid}/path/to/file`
99+
ipfs.resolve(path, (err, resolved) => {
100+
expect(err).to.not.exist()
101+
expect(resolved).to.equal(path)
102+
done()
103+
})
104+
})
105+
})
106+
107+
it('should resolve up to the last node across multiple nodes', (done) => {
108+
const options = { format: 'dag-cbor', hashAlg: 'sha2-256' }
109+
110+
waterfall([
111+
cb => {
112+
const content = { node: { with: { file: hat() } } }
113+
ipfs.dag.put(content, options, cb)
114+
},
115+
(childCid, cb) => {
116+
const content = { path: { to: childCid } }
117+
ipfs.dag.put(content, options, (err, parentCid) => cb(err, { childCid, parentCid }))
118+
}
119+
], (err, res) => {
120+
expect(err).to.not.exist()
121+
122+
const path = `/ipfs/${res.parentCid}/path/to/node/with/file`
123+
ipfs.resolve(path, (err, resolved) => {
124+
expect(err).to.not.exist()
125+
expect(resolved).to.equal(`/ipfs/${res.childCid}/node/with/file`)
102126
done()
103127
})
104128
})

0 commit comments

Comments
 (0)