|
| 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