2017-03-21 08:24:11 +00:00
|
|
|
var should = require('should'), // jshint ignore:line
|
2017-02-02 13:46:30 +01:00
|
|
|
path = require('path'),
|
|
|
|
rewire = require('rewire'),
|
|
|
|
_ = require('lodash'),
|
|
|
|
configUtils = require('../../utils/configUtils');
|
|
|
|
|
2017-03-21 08:24:11 +00:00
|
|
|
// jscs:disable requireDotNotation
|
2014-06-04 22:26:03 +01:00
|
|
|
|
2013-12-26 12:15:10 +00:00
|
|
|
describe('Config', function () {
|
2016-04-13 11:10:40 -05:00
|
|
|
before(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
2015-12-14 20:05:11 +00:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
2014-12-14 11:31:00 +00:00
|
|
|
});
|
|
|
|
|
2017-02-02 13:46:30 +01:00
|
|
|
describe('hierarchy of config channels', function () {
|
|
|
|
var originalEnv, originalArgv, customConfig, config;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
originalEnv = _.clone(process.env);
|
|
|
|
originalArgv = _.clone(process.argv);
|
|
|
|
config = rewire('../../../server/config');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
process.env = originalEnv;
|
|
|
|
process.argv = originalArgv;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('env parameter is stronger than file', function () {
|
|
|
|
process.env['database__client'] = 'test';
|
|
|
|
|
|
|
|
customConfig = config.loadNconf({
|
|
|
|
baseConfigPath: path.join(__dirname, '../../utils/fixtures/config'),
|
|
|
|
customConfigPath: path.join(__dirname, '../../utils/fixtures/config')
|
|
|
|
});
|
|
|
|
|
|
|
|
customConfig.get('database:client').should.eql('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('argv is stronger than env parameter', function () {
|
|
|
|
process.env['database__client'] = 'test';
|
|
|
|
process.argv[2] = '--database:client=stronger';
|
|
|
|
|
|
|
|
customConfig = config.loadNconf({
|
|
|
|
baseConfigPath: path.join(__dirname, '../../utils/fixtures/config'),
|
|
|
|
customConfigPath: path.join(__dirname, '../../utils/fixtures/config')
|
|
|
|
});
|
|
|
|
|
|
|
|
customConfig.get('database:client').should.eql('stronger');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('argv or env is NOT stronger than overrides', function () {
|
|
|
|
process.env['paths__corePath'] = 'try-to-override';
|
|
|
|
process.argv[2] = '--paths:corePath=try-to-override';
|
|
|
|
|
|
|
|
customConfig = config.loadNconf({
|
|
|
|
baseConfigPath: path.join(__dirname, '../../utils/fixtures/config'),
|
|
|
|
customConfigPath: path.join(__dirname, '../../utils/fixtures/config')
|
|
|
|
});
|
|
|
|
|
|
|
|
customConfig.get('paths:corePath').should.not.containEql('try-to-override');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('overrides is stronger than every other config file', function () {
|
|
|
|
customConfig = config.loadNconf({
|
|
|
|
baseConfigPath: path.join(__dirname, '../../utils/fixtures/config'),
|
|
|
|
customConfigPath: path.join(__dirname, '../../utils/fixtures/config')
|
|
|
|
});
|
|
|
|
|
|
|
|
customConfig.get('paths:corePath').should.not.containEql('try-to-override');
|
|
|
|
customConfig.get('database:client').should.eql('sqlite3');
|
|
|
|
customConfig.get('database:connection:filename').should.eql('/hehe.db');
|
|
|
|
customConfig.get('database:debug').should.eql(true);
|
|
|
|
customConfig.get('url').should.eql('http://localhost:2368');
|
|
|
|
customConfig.get('logging:level').should.eql('error');
|
|
|
|
customConfig.get('logging:transports').should.eql(['stdout']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-05 01:40:53 -05:00
|
|
|
describe('Index', function () {
|
2013-12-28 16:01:08 +00:00
|
|
|
it('should have exactly the right keys', function () {
|
2017-02-02 13:46:30 +01:00
|
|
|
var pathConfig = configUtils.config.get('paths');
|
2013-12-28 16:01:08 +00:00
|
|
|
|
|
|
|
// This will fail if there are any extra keys
|
|
|
|
pathConfig.should.have.keys(
|
|
|
|
'appRoot',
|
2016-09-13 22:24:57 +02:00
|
|
|
'internalStoragePath',
|
|
|
|
'internalSchedulingPath',
|
2013-12-28 16:01:08 +00:00
|
|
|
'contentPath',
|
|
|
|
'corePath',
|
2016-04-14 18:32:43 +01:00
|
|
|
'internalAppPath',
|
2013-12-28 16:01:08 +00:00
|
|
|
'adminViews',
|
|
|
|
'helperTemplates',
|
2015-03-08 11:09:57 -06:00
|
|
|
'clientAssets'
|
2013-12-28 16:01:08 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have the correct values for each key', function () {
|
2017-02-02 13:46:30 +01:00
|
|
|
var pathConfig = configUtils.config.get('paths'),
|
2016-10-18 10:04:44 +02:00
|
|
|
appRoot = path.resolve(__dirname, '../../../../');
|
2013-12-28 16:01:08 +00:00
|
|
|
|
|
|
|
pathConfig.should.have.property('appRoot', appRoot);
|
2016-01-11 12:37:59 +01:00
|
|
|
});
|
|
|
|
|
2014-02-08 10:41:15 -05:00
|
|
|
it('should allow specific properties to be user defined', function () {
|
2017-02-02 13:46:30 +01:00
|
|
|
var contentPath = path.join(configUtils.config.get('paths').appRoot, 'otherContent', '/');
|
2014-01-05 01:40:53 -05:00
|
|
|
|
2016-09-13 22:24:57 +02:00
|
|
|
configUtils.set('paths:contentPath', contentPath);
|
2017-02-02 13:46:30 +01:00
|
|
|
configUtils.config.get('paths').should.have.property('contentPath', contentPath);
|
|
|
|
configUtils.config.getContentPath('images').should.eql(contentPath + 'images/');
|
2013-12-28 16:01:08 +00:00
|
|
|
});
|
|
|
|
});
|
2014-01-03 00:37:21 +00:00
|
|
|
|
2015-01-17 20:54:56 -07:00
|
|
|
describe('Storage', function () {
|
|
|
|
it('should default to local-file-store', function () {
|
2017-02-02 13:46:30 +01:00
|
|
|
configUtils.config.get('paths').should.have.property('internalStoragePath', path.join(configUtils.config.get('paths').corePath, '/server/storage/'));
|
2015-01-17 20:54:56 -07:00
|
|
|
|
2017-02-02 13:46:30 +01:00
|
|
|
configUtils.config.get('storage').should.have.property('active', {
|
2016-08-22 19:55:28 +02:00
|
|
|
images: 'local-file-store',
|
|
|
|
themes: 'local-file-store'
|
|
|
|
});
|
2015-01-17 20:54:56 -07:00
|
|
|
});
|
|
|
|
|
2016-09-13 21:47:36 +02:00
|
|
|
it('no effect: setting a custom active storage as string', function () {
|
2015-12-14 20:05:11 +00:00
|
|
|
configUtils.set({
|
2015-01-17 20:54:56 -07:00
|
|
|
storage: {
|
|
|
|
active: 's3',
|
|
|
|
s3: {}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-02 13:46:30 +01:00
|
|
|
configUtils.config.get('storage').should.have.property('active', 's3');
|
|
|
|
configUtils.config.get('storage').should.have.property('s3', {});
|
2015-01-17 20:54:56 -07:00
|
|
|
});
|
2016-08-22 19:55:28 +02:00
|
|
|
|
2016-09-13 21:47:36 +02:00
|
|
|
it('able to set storage for themes (but not officially supported!)', function () {
|
2016-08-22 19:55:28 +02:00
|
|
|
configUtils.set({
|
|
|
|
storage: {
|
|
|
|
active: {
|
2016-09-13 21:47:36 +02:00
|
|
|
images: 'local-file-store',
|
2016-08-22 19:55:28 +02:00
|
|
|
themes: 's3'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-02 13:46:30 +01:00
|
|
|
configUtils.config.get('storage').should.have.property('active', {
|
2016-08-22 19:55:28 +02:00
|
|
|
images: 'local-file-store',
|
2016-09-13 21:47:36 +02:00
|
|
|
themes: 's3'
|
2016-08-22 19:55:28 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow setting a custom active storage as object', function () {
|
|
|
|
configUtils.set({
|
|
|
|
storage: {
|
|
|
|
active: {
|
|
|
|
images: 's2',
|
2016-08-23 14:07:25 +02:00
|
|
|
themes: 'local-file-store'
|
2016-08-22 19:55:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-02 13:46:30 +01:00
|
|
|
configUtils.config.get('storage').should.have.property('active', {
|
2016-08-22 19:55:28 +02:00
|
|
|
images: 's2',
|
2016-08-23 14:07:25 +02:00
|
|
|
themes: 'local-file-store'
|
2016-08-22 19:55:28 +02:00
|
|
|
});
|
|
|
|
});
|
2015-01-17 20:54:56 -07:00
|
|
|
});
|
2014-09-10 00:06:24 -04:00
|
|
|
});
|