2011-09-16 10:49:47 +00:00
|
|
|
/*
|
|
|
|
* helpers.js: Test helpers for nconf.
|
|
|
|
*
|
2011-11-24 05:33:08 +00:00
|
|
|
* (C) 2011, Nodejitsu Inc.
|
2011-09-16 10:49:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
var assert = require('assert'),
|
|
|
|
spawn = require('child_process').spawn,
|
|
|
|
nconf = require('../lib/nconf');
|
|
|
|
|
|
|
|
exports.assertMerged = function (err, merged) {
|
|
|
|
merged = merged instanceof nconf.Provider
|
|
|
|
? merged.store.store
|
|
|
|
: merged;
|
|
|
|
|
|
|
|
assert.isNull(err);
|
|
|
|
assert.isObject(merged);
|
|
|
|
assert.isTrue(merged.apples);
|
|
|
|
assert.isTrue(merged.bananas);
|
|
|
|
assert.isObject(merged.candy);
|
|
|
|
assert.isTrue(merged.candy.something1);
|
|
|
|
assert.isTrue(merged.candy.something2);
|
|
|
|
assert.isTrue(merged.candy.something3);
|
|
|
|
assert.isTrue(merged.candy.something4);
|
|
|
|
assert.isTrue(merged.dates);
|
|
|
|
assert.isTrue(merged.elderberries);
|
|
|
|
};
|
|
|
|
|
2011-09-19 01:37:01 +00:00
|
|
|
exports.assertSystemConf = function (options) {
|
2011-09-16 10:49:47 +00:00
|
|
|
return {
|
|
|
|
topic: function () {
|
2011-09-19 01:37:01 +00:00
|
|
|
var env = null;
|
|
|
|
|
|
|
|
if (options.env) {
|
|
|
|
env = {}
|
|
|
|
Object.keys(process.env).forEach(function (key) {
|
|
|
|
env[key] = process.env[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.keys(options.env).forEach(function (key) {
|
|
|
|
env[key] = options.env[key];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-11-20 21:21:09 +00:00
|
|
|
var child = spawn('node', [options.script].concat(options.argv), { env: env });
|
|
|
|
child.stdout.once('data', this.callback.bind(this, null));
|
2011-09-16 10:49:47 +00:00
|
|
|
},
|
|
|
|
"should respond with the value passed into the script": function (_, data) {
|
|
|
|
assert.equal(data.toString(), 'foobar');
|
|
|
|
}
|
|
|
|
}
|
2011-11-19 00:29:01 +00:00
|
|
|
}
|
|
|
|
|