forked from Nordstrom/config
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add loadFromFile function to enable custom config location Nordstrom#17
- Loading branch information
Lucien Zuercher
committed
Apr 1, 2020
1 parent
6fbbb26
commit b8d99cf
Showing
5 changed files
with
92 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
var1: val1 | ||
var2: val2 | ||
|
||
obj1: | ||
var1: objval1 | ||
var2: objval2 | ||
|
||
|
||
list1: | ||
- listval1 | ||
- listval2 |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
lower: ${envId} | ||
upper: ${ENVID} | ||
|
||
obj1: | ||
obj2: | ||
lower: ${envId} | ||
upper: ${ENVID} | ||
|
||
setting1: settingVal | ||
|
||
list1: | ||
- ${envId} | ||
- ${ENVID} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict' | ||
|
||
require('should') | ||
const path = require('path') | ||
|
||
describe('Config env from load', function () { | ||
let config, env | ||
|
||
before(function () { | ||
env = 'loadenv' | ||
config = require('../').loadFromFile(path.join(__dirname, 'configs/custom', 'env.yml'), env) | ||
}) | ||
|
||
it('should have env variables at top', function () { | ||
config.lower.should.equal(env) | ||
config.upper.should.equal(env.toUpperCase()) | ||
}) | ||
|
||
it('should have env variables in obj', function () { | ||
config.obj1.obj2.lower.should.equal(env) | ||
config.obj1.obj2.upper.should.equal(env.toUpperCase()) | ||
}) | ||
|
||
it('should have env variables in obj', function () { | ||
config.list1[0].should.equal(env) | ||
config.list1[1].should.equal(env.toUpperCase()) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
require('should') | ||
const path = require('path') | ||
|
||
describe('Config file provided', function () { | ||
var config | ||
|
||
before(function () { | ||
config = require('../').loadFromFile(path.join(__dirname, 'configs/custom', 'custom-config.yml')) | ||
}) | ||
|
||
it('should have top variables', function () { | ||
config.var1.should.equal('val1') | ||
config.var2.should.equal('val2') | ||
}) | ||
|
||
it('should have obj variables', function () { | ||
config.obj1.var1.should.equal('objval1') | ||
config.obj1.var2.should.equal('objval2') | ||
}) | ||
|
||
it('should have obj variables', function () { | ||
config.list1[0].should.equal('listval1') | ||
config.list1[1].should.equal('listval2') | ||
}) | ||
}) |