migrate-options unit test added
This commit is contained in:
parent
dc1ed52357
commit
cdfc84a96a
2 changed files with 65 additions and 27 deletions
|
|
@ -13,7 +13,7 @@ const paths = _.wrap(_.split, path.sep)
|
|||
// /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => 3
|
||||
const indexOfLs = _.flow(paths, _.wrap(_.indexOf, 'lamassu-server'))
|
||||
|
||||
module.exports = {run, mapKeyValuesDeep}
|
||||
module.exports = {run, mapKeyValuesDeep, updateOptionBasepath}
|
||||
|
||||
function mapKeyValuesDeep (cb, obj, key) {
|
||||
if (_.isArray(obj)) {
|
||||
|
|
@ -25,21 +25,7 @@ function mapKeyValuesDeep (cb, obj, key) {
|
|||
}
|
||||
}
|
||||
|
||||
async function run () {
|
||||
// load defaults
|
||||
const defaultOpts = require('../lamassu-default')
|
||||
|
||||
// load current opts
|
||||
const options = load()
|
||||
const currentOpts = options.opts
|
||||
|
||||
// check if there are new options to add
|
||||
let result = _.mergeAll([defaultOpts, currentOpts])
|
||||
|
||||
// get all the options
|
||||
// that ends with "Path" suffix
|
||||
console.log(`Detected lamassu-server basepath: ${currentBasePath}`)
|
||||
_.map(optionName => {
|
||||
function updateOptionBasepath (result, optionName) {
|
||||
const currentPath = _.get(optionName, result)
|
||||
|
||||
// process only keys that contains
|
||||
|
|
@ -63,7 +49,30 @@ async function run () {
|
|||
console.log(`Migrating option ${optionName} to new path ${newPath}`)
|
||||
result[optionName] = newPath
|
||||
}
|
||||
}, ['seedPath', 'caPath', 'certPath', 'keyPath', 'lamassuCaPath'])
|
||||
}
|
||||
|
||||
async function run () {
|
||||
// load defaults
|
||||
const defaultOpts = require('../lamassu-default')
|
||||
|
||||
// load current opts
|
||||
const options = load()
|
||||
const currentOpts = options.opts
|
||||
|
||||
// check if there are new options to add
|
||||
let result = _.mergeAll([defaultOpts, currentOpts])
|
||||
|
||||
// get all the options
|
||||
// that ends with "Path" suffix
|
||||
console.log(`Detected lamassu-server basepath: ${currentBasePath}`)
|
||||
_.each(_.wrap(updateOptionBasepath, result),
|
||||
[
|
||||
'seedPath',
|
||||
'caPath',
|
||||
'certPath',
|
||||
'keyPath',
|
||||
'lamassuCaPath'
|
||||
])
|
||||
|
||||
const shouldMigrate = !_.isEqual(result, currentOpts) || _.has('lamassuServerPath', result)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
import test from 'ava'
|
||||
import _ from 'lodash/fp'
|
||||
import path from 'path'
|
||||
|
||||
import {mapKeyValuesDeep} from '../../lib/migrate-options'
|
||||
import {mapKeyValuesDeep, updateOptionBasepath} from '../../lib/migrate-options'
|
||||
|
||||
const currentBasePath = path.dirname(path.dirname(__dirname))
|
||||
|
||||
test('mapKeyValuesDeep', t => {
|
||||
const test = {
|
||||
|
|
@ -33,3 +36,29 @@ test('mapKeyValuesDeep', t => {
|
|||
|
||||
t.deepEqual(result, expected)
|
||||
})
|
||||
|
||||
test('updateOptionBasepath', t => {
|
||||
const test = {
|
||||
someBooleanOption: true,
|
||||
someStringOption: 'my-custom-option',
|
||||
customExternalPath: '/usr/lib/node_modules/ava',
|
||||
seedPath: '/etc/lamassu/seeds/seed.txt',
|
||||
caPath: '/usr/lib/node_modules/lamassu-server/certs/Lamassu_OP_Root_CA.pem'
|
||||
}
|
||||
const expected = {
|
||||
someBooleanOption: true,
|
||||
someStringOption: 'my-custom-option',
|
||||
customExternalPath: '/usr/lib/node_modules/ava',
|
||||
seedPath: '/etc/lamassu/seeds/seed.txt',
|
||||
caPath: path.join(currentBasePath, 'certs/Lamassu_OP_Root_CA.pem')
|
||||
}
|
||||
|
||||
let result = _.clone(test)
|
||||
|
||||
_.each(
|
||||
_.wrap(updateOptionBasepath, result),
|
||||
_.keys(test)
|
||||
)
|
||||
|
||||
t.deepEqual(result, expected)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue