This repository was 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
/
Copy pathtest-config.js
93 lines (78 loc) · 2.55 KB
/
test-config.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
83
84
85
86
87
88
89
90
91
92
93
/* eslint-env mocha */
'use strict'
const expect = require('chai').expect
const fs = require('fs')
const path = require('path')
module.exports = (ctl) => {
describe('.config', () => {
const configPath = path.join(__dirname, '../../repo-tests-run/config')
let updatedConfig
before(() => {
updatedConfig = () => JSON.parse(fs.readFileSync(configPath, 'utf8'))
})
it('.get returns error for request with invalid argument', (done) => {
ctl.config.get('kittens', (err, res) => {
expect(err).to.exist
done()
})
})
it('.get returns value for request with argument', (done) => {
ctl.config.get('API.HTTPHeaders', (err, value) => {
expect(err).not.to.exist
expect(value).to.equal(null)
done()
})
})
it('.set updates value for request with both args', (done) => {
ctl.config.set('Datastore.Path', 'kitten', (err) => {
expect(err).not.to.exist
done()
})
})
it('.set returns error for request with both args and JSON flag with invalid JSON argument', (done) => {
ctl.config.set('Datastore.Path', 'kitten', { json: true }, (err) => {
expect(err).to.exist
done()
})
})
it('.set updates value for request with both args and bool flag and true argument', (done) => {
ctl.config.set('Datastore.Path', true, (err) => {
expect(err).not.to.exist
done()
})
})
it('.set updates value for request with both args and bool flag and false argument', (done) => {
ctl.config.set('Datastore.Path', false, (err) => {
expect(err).not.to.exist
done()
})
})
it('.get updatedConfig', (done) => {
ctl.config.get((err, config) => {
expect(err).not.to.exist
expect(config).to.be.eql(updatedConfig())
done()
})
})
// This one is one stale mode till go-ipfs decides
// what to do with the .replace command
describe('.replace', () => {
it('returns error if the config is invalid', (done) => {
const filePath = 'test/test-data/badconfig'
ctl.config.replace(filePath, (err) => {
expect(err).to.exist
done()
})
})
it('updates value', (done) => {
const filePath = 'test/test-data/otherconfig'
const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8'))
ctl.config.replace(filePath, (err) => {
expect(err).not.to.exist
expect(expectedConfig).to.deep.equal(updatedConfig())
done()
})
})
})
})
}