forked from db-migrate/node-db-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Implemented default values for undefined env vars
closes db-migrate#765 Signed-off-by: Kael Shipman <[email protected]>
- Loading branch information
1 parent
67b6a4b
commit 3cb7bdf
Showing
4 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,10 @@ lab.experiment('config', function () { | |
|
||
function () { | ||
process.env.DB_MIGRATE_TEST_VAR = 'username_from_env'; | ||
process.env.EMPTY_VAR = ''; | ||
if (typeof process.env.NOT_SET !== 'undefined') { | ||
delete process.env.NOT_SET; | ||
} | ||
var configPath = path.join(__dirname, 'database_with_env.json'); | ||
var _config = config.load(configPath, 'prod'); | ||
|
||
|
@@ -98,6 +102,16 @@ lab.experiment('config', function () { | |
Code.expect(_config.prod.username).to.equal('username_from_env'); | ||
} | ||
); | ||
lab.test( | ||
'should load default value from not set env var', () => { | ||
Code.expect(_config.prod.password).to.equal('my-password'); | ||
} | ||
); | ||
lab.test( | ||
'should use value from env var even when empty, rather than default', () => { | ||
Code.expect(_config.prod.host).to.equal(''); | ||
} | ||
); | ||
} | ||
); | ||
|
||
|
@@ -122,6 +136,29 @@ lab.experiment('config', function () { | |
} | ||
); | ||
|
||
lab.experiment( | ||
'loading from a file from default when ENV URL is not set', | ||
|
||
function () { | ||
if (typeof process.env.DB_MIGRATE_TEST_VAR !== "undefined") { | ||
delete process.env.DB_MIGRATE_TEST_VAR; | ||
} | ||
var configPath = path.join(__dirname, 'database_with_env_url.json'); | ||
var _config = config.load(configPath, 'prod'); | ||
|
||
lab.test( | ||
'should load the url from default when env var not set', () => { | ||
var current = _config.getCurrent(); | ||
Code.expect(current.settings.driver).to.equal('postgres'); | ||
Code.expect(current.settings.user).to.equal('uname'); | ||
Code.expect(current.settings.password).to.equal('pw'); | ||
Code.expect(current.settings.host).to.equal('server.com'); | ||
Code.expect(current.settings.database).to.equal('dbname'); | ||
} | ||
); | ||
} | ||
); | ||
|
||
lab.experiment('loading from an URL', function () { | ||
var databaseUrl = 'postgres://uname:[email protected]/dbname'; | ||
var _config = config.loadUrl(databaseUrl, 'dev'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"prod": {"ENV": "DB_MIGRATE_TEST_VAR"} | ||
"prod": {"ENV": "DB_MIGRATE_TEST_VAR", "default": "postgres://uname:[email protected]/dbname"} | ||
} |