This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathset.js
82 lines (62 loc) · 2.15 KB
/
set.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
79
80
81
82
/* eslint-env mocha */
'use strict'
const { getDescribe, getIt, expect } = require('../utils/mocha')
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.config.set', function () {
this.timeout(30 * 1000)
let ipfs
before(async () => {
ipfs = (await common.spawn()).api
})
after(() => common.clean())
it('should set a new key', async () => {
await ipfs.config.set('Fruit', 'banana')
const fruit = await ipfs.config.get('Fruit')
expect(fruit).to.equal('banana')
})
it('should set an already existing key', async () => {
await ipfs.config.set('Fruit', 'morango')
const fruit = await ipfs.config.get('Fruit')
expect(fruit).to.equal('morango')
})
it('should set a number', async () => {
const key = 'Discovery.MDNS.Interval'
const val = 11
await ipfs.config.set(key, val)
const result = await ipfs.config.get(key)
expect(result).to.equal(val)
})
it('should set a boolean', async () => {
const value = true
const key = 'Discovery.MDNS.Enabled'
await ipfs.config.set(key, value)
expect(await ipfs.config.get(key)).to.equal(value)
})
it('should set the other boolean', async () => {
const value = false
const key = 'Discovery.MDNS.Enabled'
await ipfs.config.set(key, value)
expect(await ipfs.config.get(key)).to.equal(value)
})
it('should set a JSON object', async () => {
const key = 'API.HTTPHeaders.Access-Control-Allow-Origin'
const val = ['http://example.io']
await ipfs.config.set(key, val)
const result = await ipfs.config.get(key)
expect(result).to.deep.equal(val)
})
it('should fail on non valid key', () => {
return expect(ipfs.config.set(Buffer.from('heeey'), '')).to.eventually.be.rejected()
})
it('should fail on non valid value', () => {
return expect(ipfs.config.set('Fruit', Buffer.from('abc'))).to.eventually.be.rejected()
})
})
}