Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit d44de4c

Browse files
committed
test: add resolve IPFS path test
License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
1 parent 3ba4513 commit d44de4c

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/http/api/routes/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ module.exports = (server) => {
2121
require('./dns')(server)
2222
require('./key')(server)
2323
require('./stats')(server)
24+
require('./resolve')(server)
2425
}

test/cli/resolve.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const Path = require('path')
4+
const path = require('path')
55
const expect = require('chai').expect
66
const isIpfs = require('is-ipfs')
77

@@ -14,19 +14,39 @@ describe('resolve', () => runOnAndOff((thing) => {
1414
ipfs = thing.ipfs
1515
})
1616

17-
it('should resolve an IPFS hash', (done) => {
18-
const path = '/src/init-files/init-docs/readme'
17+
it('should resolve an IPFS hash', () => {
18+
const filePath = path.join(process.cwd(), '/src/init-files/init-docs/readme')
1919
let hash
2020

21-
return ipfs(`add ${Path.join(process.cwd(), path)}`)
21+
return ipfs(`add ${filePath}`)
2222
.then((out) => {
2323
hash = out.split(' ')[1]
24-
console.log(out)
2524
expect(isIpfs.cid(hash)).to.be.true()
26-
return ipfs(`resolve ${hash}`)
25+
return ipfs(`resolve /ipfs/${hash}`)
2726
})
2827
.then((out) => {
2928
expect(out).to.contain(`/ipfs/${hash}`)
3029
})
3130
})
31+
32+
it('should resolve an IPFS path link', () => {
33+
const filePath = path.join(process.cwd(), '/src/init-files/init-docs/readme')
34+
let fileHash, rootHash
35+
36+
return ipfs(`add ${filePath} --wrap-with-directory`)
37+
.then((out) => {
38+
const lines = out.split('\n')
39+
40+
fileHash = lines[0].split(' ')[1]
41+
rootHash = lines[1].split(' ')[1]
42+
43+
expect(isIpfs.cid(fileHash)).to.be.true()
44+
expect(isIpfs.cid(rootHash)).to.be.true()
45+
46+
return ipfs(`resolve /ipfs/${rootHash}/readme`)
47+
})
48+
.then((out) => {
49+
expect(out).to.contain(`/ipfs/${fileHash}`)
50+
})
51+
})
3252
}))

0 commit comments

Comments
 (0)