Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit e45f39c

Browse files
dirkmcAlan Shaw
authored and
Alan Shaw
committed
feat: tests for config profile endpoint (#488)
1 parent f8e5628 commit e45f39c

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

src/config/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const { createSuite } = require('../utils/suite')
44
const tests = {
55
get: require('./get'),
66
set: require('./set'),
7-
replace: require('./replace')
7+
replace: require('./replace'),
8+
profile: require('./profile')
89
}
910

1011
module.exports = createSuite(tests)

src/config/profile.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const { getDescribe, getIt, expect } = require('../utils/mocha')
5+
const waterfall = require('async/waterfall')
6+
7+
module.exports = (createCommon, options) => {
8+
const describe = getDescribe(options)
9+
const it = getIt(options)
10+
const common = createCommon()
11+
12+
describe('.config.profile', function () {
13+
this.timeout(30 * 1000)
14+
let ipfs
15+
16+
before(function (done) {
17+
// CI takes longer to instantiate the daemon, so we need to increase the
18+
// timeout for the before step
19+
this.timeout(60 * 1000)
20+
21+
common.setup((err, factory) => {
22+
expect(err).to.not.exist()
23+
factory.spawnNode((err, node) => {
24+
expect(err).to.not.exist()
25+
ipfs = node
26+
done()
27+
})
28+
})
29+
})
30+
31+
after((done) => common.teardown(done))
32+
33+
it('should output changes but not save them for dry run', (done) => {
34+
let config
35+
waterfall([
36+
(cb) => ipfs.config.get(cb),
37+
(_config, cb) => {
38+
config = _config
39+
ipfs.config.profile('lowpower', { dryRun: true }, cb)
40+
},
41+
(diff, cb) => {
42+
expect(diff.oldCfg.Swarm.ConnMgr.LowWater).to.not.equal(diff.newCfg.Swarm.ConnMgr.LowWater)
43+
ipfs.config.get(cb)
44+
},
45+
(newConfig, cb) => {
46+
expect(newConfig.Swarm.ConnMgr.LowWater).to.equal(config.Swarm.ConnMgr.LowWater)
47+
cb()
48+
}
49+
], done)
50+
})
51+
52+
it('should set a config profile', (done) => {
53+
let diff
54+
waterfall([
55+
(cb) => ipfs.config.get(cb),
56+
(config, cb) => ipfs.config.profile('lowpower', cb),
57+
(_diff, cb) => {
58+
diff = _diff
59+
expect(diff.oldCfg.Swarm.ConnMgr.LowWater).to.not.equal(diff.newCfg.Swarm.ConnMgr.LowWater)
60+
ipfs.config.get(cb)
61+
},
62+
(newConfig, cb) => {
63+
expect(newConfig.Swarm.ConnMgr.LowWater).to.equal(diff.newCfg.Swarm.ConnMgr.LowWater)
64+
cb()
65+
}
66+
], done)
67+
})
68+
})
69+
}

0 commit comments

Comments
 (0)