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
/
get.js
73 lines (55 loc) · 1.95 KB
/
get.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
/* eslint-env mocha */
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testGet (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.config.get', function () {
this.timeout(30 * 1000)
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
before(async () => { ipfs = (await factory.spawn()).api })
after(() => factory.clean())
it('should fail with error', async () => {
// @ts-expect-error missing arg
await expect(ipfs.config.get()).to.eventually.rejectedWith('key argument is required')
})
it('should retrieve a value through a key', async () => {
const peerId = await ipfs.config.get('Identity.PeerID')
expect(peerId).to.exist()
})
it('should retrieve a value through a nested key', async () => {
const swarmAddrs = await ipfs.config.get('Addresses.Swarm')
expect(swarmAddrs).to.exist()
})
it('should fail on non valid key', () => {
// @ts-expect-error invalid arg
return expect(ipfs.config.get(1234)).to.eventually.be.rejected()
})
it('should fail on non existent key', () => {
return expect(ipfs.config.get('Bananas')).to.eventually.be.rejected()
})
})
describe('.config.getAll', function () {
this.timeout(30 * 1000)
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
before(async () => { ipfs = (await factory.spawn()).api })
after(() => factory.clean())
it('should retrieve the whole config', async () => {
const config = await ipfs.config.getAll()
expect(config).to.be.an('object')
})
it('should retrieve the whole config with options', async () => {
const config = await ipfs.config.getAll({ signal: undefined })
expect(config).to.be.an('object')
})
})
}