From 7794b91d20b670b3244e10f010ab4089cb88d738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 14 Jan 2021 17:16:33 +0000 Subject: [PATCH] feat: flag option to toggle test db --- lib/options-loader.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/options-loader.js b/lib/options-loader.js index 970076b1..37605be5 100644 --- a/lib/options-loader.js +++ b/lib/options-loader.js @@ -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)