From e45f39c2b9b6a4d4f9e0b7debf7c21cd7a301ca0 Mon Sep 17 00:00:00 2001 From: dirkmc Date: Wed, 17 Jul 2019 07:45:07 -0400 Subject: [PATCH] feat: tests for config profile endpoint (#488) --- src/config/index.js | 3 +- src/config/profile.js | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/config/profile.js diff --git a/src/config/index.js b/src/config/index.js index d17d3423..a9c31ec1 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -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) diff --git a/src/config/profile.js b/src/config/profile.js new file mode 100644 index 00000000..9722d06c --- /dev/null +++ b/src/config/profile.js @@ -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) + }) + }) +}