2011-09-16 10:49:47 +00:00
|
|
|
/*
|
|
|
|
* helpers.js: Test helpers for nconf.
|
|
|
|
*
|
2014-11-26 06:31:48 +00:00
|
|
|
* (C) 2011, Charlie Robbins and the Contributors.
|
2011-09-16 10:49:47 +00:00
|
|
|
*
|
|
|
|
*/
|
2014-11-26 06:05:06 +00:00
|
|
|
|
2019-04-30 02:26:02 +00:00
|
|
|
var spawn = require('child_process').spawn;
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var nconf = require('../lib/nconf');
|
2011-09-16 10:49:47 +00:00
|
|
|
|
|
|
|
exports.assertMerged = function (err, merged) {
|
2014-11-26 06:05:06 +00:00
|
|
|
merged = merged instanceof nconf.Provider
|
2011-09-16 10:49:47 +00:00
|
|
|
? merged.store.store
|
|
|
|
: merged;
|
2014-11-26 06:05:06 +00:00
|
|
|
|
2019-04-30 02:26:02 +00:00
|
|
|
expect()
|
|
|
|
expect(err).toBeNull();
|
|
|
|
expect(typeof merged).toBe('object');
|
|
|
|
expect(merged.apples).toBeTruthy();
|
|
|
|
expect(merged.bananas).toBeTruthy();
|
|
|
|
expect(typeof merged.candy).toBe('object');
|
|
|
|
expect(merged.candy.something1).toBeTruthy();
|
|
|
|
expect(merged.candy.something2).toBeTruthy();
|
|
|
|
expect(merged.candy.something3).toBeTruthy();
|
|
|
|
expect(merged.candy.something4).toBeTruthy();
|
|
|
|
expect(merged.dates).toBeTruthy();
|
|
|
|
expect(merged.elderberries).toBeTruthy();
|
2011-09-16 10:49:47 +00:00
|
|
|
};
|
|
|
|
|
2019-04-30 02:26:02 +00:00
|
|
|
//FIXME TODO
|
2011-09-19 01:37:01 +00:00
|
|
|
exports.assertSystemConf = function (options) {
|
2019-04-30 02:26:02 +00:00
|
|
|
return done => {
|
|
|
|
var env = null;
|
2014-11-26 06:05:06 +00:00
|
|
|
|
2019-04-30 02:26:02 +00:00
|
|
|
if (options.env) {
|
|
|
|
env = {}
|
|
|
|
Object.keys(process.env).forEach(function (key) {
|
|
|
|
env[key] = process.env[key];
|
|
|
|
});
|
2014-11-26 06:05:06 +00:00
|
|
|
|
2019-04-30 02:26:02 +00:00
|
|
|
Object.keys(options.env).forEach(function (key) {
|
|
|
|
env[key] = options.env[key];
|
|
|
|
});
|
2011-09-16 10:49:47 +00:00
|
|
|
}
|
2019-04-30 02:26:02 +00:00
|
|
|
|
|
|
|
var child = spawn('node', [options.script].concat(options.argv), {env: env});
|
|
|
|
child.stdout.once('data', data => {
|
|
|
|
expect(data.toString()).toEqual('foobar');
|
|
|
|
done();
|
|
|
|
});
|
2011-09-16 10:49:47 +00:00
|
|
|
}
|
2011-11-19 00:29:01 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 02:33:00 +00:00
|
|
|
// copy a file
|
|
|
|
exports.cp = function (from, to, callback) {
|
|
|
|
fs.readFile(from, function (err, data) {
|
|
|
|
if (err) return callback(err);
|
|
|
|
fs.writeFile(to, data, callback);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fixture = function (file) {
|
2012-07-10 05:47:28 +00:00
|
|
|
return path.join(__dirname, 'fixtures', file);
|
2014-11-26 06:05:06 +00:00
|
|
|
};
|