From 142a3736d32730e80705ddd7991240cbb714f526 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 3 Oct 2019 07:27:56 +0100 Subject: [PATCH] feat: add test for listing config profiles This is only in js-IPFS for the time being --- src/config/index.js | 2 +- src/config/{profile.js => profiles/apply.js} | 28 ++--------- src/config/profiles/index.js | 9 ++++ src/config/profiles/list.js | 50 ++++++++++++++++++++ 4 files changed, 64 insertions(+), 25 deletions(-) rename src/config/{profile.js => profiles/apply.js} (56%) create mode 100644 src/config/profiles/index.js create mode 100644 src/config/profiles/list.js diff --git a/src/config/index.js b/src/config/index.js index a9c31ec1..783dacdc 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -5,7 +5,7 @@ const tests = { get: require('./get'), set: require('./set'), replace: require('./replace'), - profile: require('./profile') + profiles: require('./profiles') } module.exports = createSuite(tests) diff --git a/src/config/profile.js b/src/config/profiles/apply.js similarity index 56% rename from src/config/profile.js rename to src/config/profiles/apply.js index 9722d06c..9329f565 100644 --- a/src/config/profile.js +++ b/src/config/profiles/apply.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ 'use strict' -const { getDescribe, getIt, expect } = require('../utils/mocha') +const { getDescribe, getIt, expect } = require('../../utils/mocha') const waterfall = require('async/waterfall') module.exports = (createCommon, options) => { @@ -9,7 +9,7 @@ module.exports = (createCommon, options) => { const it = getIt(options) const common = createCommon() - describe('.config.profile', function () { + describe('.config.profiles.apply', function () { this.timeout(30 * 1000) let ipfs @@ -30,30 +30,10 @@ module.exports = (createCommon, options) => { 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) => { + it('should apply a config profile', (done) => { let diff waterfall([ - (cb) => ipfs.config.get(cb), - (config, cb) => ipfs.config.profile('lowpower', cb), + (cb) => ipfs.config.profiles.apply('lowpower', cb), (_diff, cb) => { diff = _diff expect(diff.oldCfg.Swarm.ConnMgr.LowWater).to.not.equal(diff.newCfg.Swarm.ConnMgr.LowWater) diff --git a/src/config/profiles/index.js b/src/config/profiles/index.js new file mode 100644 index 00000000..0a70eb4c --- /dev/null +++ b/src/config/profiles/index.js @@ -0,0 +1,9 @@ +'use strict' +const { createSuite } = require('../../utils/suite') + +const tests = { + list: require('./list'), + apply: require('./apply') +} + +module.exports = createSuite(tests) diff --git a/src/config/profiles/list.js b/src/config/profiles/list.js new file mode 100644 index 00000000..0b080714 --- /dev/null +++ b/src/config/profiles/list.js @@ -0,0 +1,50 @@ +/* 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.profiles.list', 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 list config profiles', (done) => { + waterfall([ + (cb) => ipfs.config.profiles.list(cb), + (profiles, cb) => { + expect(profiles).to.be.an('array') + expect(profiles).not.to.be.empty() + + profiles.forEach(profile => { + expect(profile.name).to.be.a('string') + expect(profile.description).to.be.a('string') + }) + + cb() + } + ], done) + }) + }) +}