Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Last active December 26, 2015 14:08
Show Gist options
  • Save ericelliott/7162920 to your computer and use it in GitHub Desktop.
Save ericelliott/7162920 to your computer and use it in GitHub Desktop.
How do you specify configuration dependencies for your app? Say you have app configuration that depends on other bits of app configuration (for example, some config lives at an http endpoint, but you need to read the endpoint URL from some other config before you can hit it).
/**
* Add support for config dependencies. This allows you to specify
* configuration that other configuration depends upon.
*/
test('Dependencies v4.callback', function (t) {
qconf.clear();
var subject = {hello: 'world'},
sentence = function (subject, cb) {
cb(null, 'goobye, cruel ' + subject);
};
// Callback = Return undefined.
qconf([{
name: 'subject',
source: subject
},
{
name: 'sentence',
source: sentence,
dependencies: ['subject']
}
],
function (err, conf) {
t.error('Should not cause error.');
t.equal(conf.get(sentence), 'goodbye, cruel world');
t.end();
});
});
test('Dependencies v4.promise', function (t) {
qconf.clear();
var subject = {hello: 'world'},
sentence = function (subject, cb) {
cb(null, 'goobye, cruel ' + subject);
};
// No callback = return promise.
loadConfig = qconf([{
name: 'subject',
source: subject
},
{
name: 'sentence',
source: sentence,
dependencies: ['subject']
}
]).then(function (conf) {
t.equal(conf.get(sentence), 'goodbye, cruel world');
t.end();
}, function (err) {
t.error(err, 'Should not cause error.')
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment