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

Commit

Permalink
feat: tests for config profile endpoint (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc authored and alanshaw committed Jul 17, 2019
1 parent f8e5628 commit e45f39c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const { createSuite } = require('../utils/suite')
const tests = {
get: require('./get'),
set: require('./set'),
replace: require('./replace')
replace: require('./replace'),
profile: require('./profile')
}

module.exports = createSuite(tests)
69 changes: 69 additions & 0 deletions src/config/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-env mocha */
'use strict'

const { getDescribe, getIt, expect } = require('../utils/mocha')
const waterfall = require('async/waterfall')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

describe('.config.profile', function () {
this.timeout(30 * 1000)
let ipfs

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
done()
})
})
})

after((done) => common.teardown(done))

it('should output changes but not save them for dry run', (done) => {
let config
waterfall([
(cb) => ipfs.config.get(cb),
(_config, cb) => {
config = _config
ipfs.config.profile('lowpower', { dryRun: true }, cb)
},
(diff, cb) => {
expect(diff.oldCfg.Swarm.ConnMgr.LowWater).to.not.equal(diff.newCfg.Swarm.ConnMgr.LowWater)
ipfs.config.get(cb)
},
(newConfig, cb) => {
expect(newConfig.Swarm.ConnMgr.LowWater).to.equal(config.Swarm.ConnMgr.LowWater)
cb()
}
], done)
})

it('should set a config profile', (done) => {
let diff
waterfall([
(cb) => ipfs.config.get(cb),
(config, cb) => ipfs.config.profile('lowpower', cb),
(_diff, cb) => {
diff = _diff
expect(diff.oldCfg.Swarm.ConnMgr.LowWater).to.not.equal(diff.newCfg.Swarm.ConnMgr.LowWater)
ipfs.config.get(cb)
},
(newConfig, cb) => {
expect(newConfig.Swarm.ConnMgr.LowWater).to.equal(diff.newCfg.Swarm.ConnMgr.LowWater)
cb()
}
], done)
})
})
}

0 comments on commit e45f39c

Please sign in to comment.