feat: flag option to toggle test db

This commit is contained in:
Sérgio Salgado 2021-01-14 17:16:33 +00:00 committed by Josh Harvey
parent c75319d166
commit 7794b91d20

View file

@ -3,6 +3,8 @@ const path = require('path')
const os = require('os')
const argv = require('minimist')(process.argv.slice(2))
const STRESS_TEST_DB = 'psql://postgres:postgres123@localhost/lamassu_stress'
/**
* @return {{path: string, opts: any}}
*/
@ -25,17 +27,29 @@ function load () {
try {
const globalConfigPath = path.resolve('/etc', 'lamassu', 'lamassu.json')
return {
const config = {
path: globalConfigPath,
opts: JSON.parse(fs.readFileSync(globalConfigPath))
}
if (argv.testDB) {
config.opts.postgresql = STRESS_TEST_DB
}
return config
} catch (_) {
try {
const homeConfigPath = path.resolve(os.homedir(), '.lamassu', 'lamassu.json')
return {
const config = {
path: homeConfigPath,
opts: JSON.parse(fs.readFileSync(homeConfigPath))
}
if (argv.testDB) {
config.opts.postgresql = STRESS_TEST_DB
}
return config
} catch (_) {
console.error("Couldn't open lamassu.json config file.")
process.exit(1)