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

Commit

Permalink
feat: add test for listing config profiles
Browse files Browse the repository at this point in the history
This is only in js-IPFS for the time being
  • Loading branch information
achingbrain committed Oct 4, 2019
1 parent b91c0c8 commit 142a373
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 4 additions & 24 deletions src/config/profile.js → src/config/profiles/apply.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* 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) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

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

Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/config/profiles/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'
const { createSuite } = require('../../utils/suite')

const tests = {
list: require('./list'),
apply: require('./apply')
}

module.exports = createSuite(tests)
50 changes: 50 additions & 0 deletions src/config/profiles/list.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
}

0 comments on commit 142a373

Please sign in to comment.