This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
resolve.js
78 lines (59 loc) · 1.94 KB
/
resolve.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* eslint-env mocha */
'use strict'
const { expect } = require('aegir/utils/chai')
const CID = require('cids')
const cli = require('./utils/cli')
const sinon = require('sinon')
const defaultOptions = {
recursive: true,
cidBase: undefined,
timeout: undefined
}
describe('resolve', () => {
let ipfs
const cid = new CID('Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z')
beforeEach(() => {
ipfs = {
resolve: sinon.stub()
}
})
it('resolves a CID', async () => {
const resolved = `/ipfs/${cid}`
ipfs.resolve.withArgs(cid.toString(), defaultOptions).resolves(resolved)
const out = await cli(`resolve ${cid}`, { ipfs })
expect(out).to.equal(resolved + '\n')
})
it('resolves a CID recursively', async () => {
const resolved = `/ipfs/${cid}`
ipfs.resolve.withArgs(cid.toString(), {
...defaultOptions,
recursive: true
}).resolves(resolved)
const out = await cli(`resolve ${cid} --recursive`, { ipfs })
expect(out).to.equal(resolved + '\n')
})
it('resolves a CID recursively (short option)', async () => {
const resolved = `/ipfs/${cid}`
ipfs.resolve.withArgs(cid.toString(), {
...defaultOptions,
recursive: true
}).resolves(resolved)
const out = await cli(`resolve ${cid} -r`, { ipfs })
expect(out).to.equal(resolved + '\n')
})
it('resolves a CID with a timeout', async () => {
const resolved = `/ipfs/${cid}`
ipfs.resolve.withArgs(cid.toString(), {
...defaultOptions,
timeout: 1000
}).resolves(resolved)
const out = await cli(`resolve ${cid} --timeout 1s`, { ipfs })
expect(out).to.equal(resolved + '\n')
})
it('strips control characters when resolving a CID', async () => {
const resolved = `/ipfs/${cid}/derp/\bherp`
ipfs.resolve.withArgs(cid.toString(), defaultOptions).resolves(resolved)
const out = await cli(`resolve ${cid}`, { ipfs })
expect(out).to.equal(`/ipfs/${cid}/derp/herp\n`)
})
})