2017-02-02 15:46:30 +03:00
|
|
|
// jscs:disable requireDotNotation
|
|
|
|
|
|
|
|
var should = require('should'),
|
|
|
|
path = require('path'),
|
|
|
|
rewire = require('rewire'),
|
|
|
|
_ = require('lodash'),
|
|
|
|
configUtils = require('../../utils/configUtils');
|
|
|
|
|
|
|
|
should.equal(true, true);
|
2014-06-05 01:26:03 +04:00
|
|
|
|
2013-12-26 16:15:10 +04:00
|
|
|
describe('Config', function () {
|
2016-04-13 19:10:40 +03:00
|
|
|
before(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
2014-12-14 14:31:00 +03:00
|
|
|
});
|
|
|
|
|
2017-02-02 15:46:30 +03: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 10:40:53 +04:00
|
|
|
describe('Index', function () {
|
2013-12-28 20:01:08 +04:00
|
|
|
it('should have exactly the right keys', function () {
|
2017-02-02 15:46:30 +03:00
|
|
|
var pathConfig = configUtils.config.get('paths');
|
2013-12-28 20:01:08 +04:00
|
|
|
|
|
|
|
// This will fail if there are any extra keys
|
|
|
|
pathConfig.should.have.keys(
|
|
|
|
'appRoot',
|
2016-09-13 23:24:57 +03:00
|
|
|
'internalStoragePath',
|
|
|
|
'internalSchedulingPath',
|
2013-12-28 20:01:08 +04:00
|
|
|
'contentPath',
|
|
|
|
'corePath',
|
2016-04-14 20:32:43 +03:00
|
|
|
'internalAppPath',
|
2013-12-28 20:01:08 +04:00
|
|
|
'adminViews',
|
|
|
|
'helperTemplates',
|
2015-03-08 20:09:57 +03:00
|
|
|
'clientAssets'
|
2013-12-28 20:01:08 +04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have the correct values for each key', function () {
|
2017-02-02 15:46:30 +03:00
|
|
|
var pathConfig = configUtils.config.get('paths'),
|
2016-10-18 11:04:44 +03:00
|
|
|
appRoot = path.resolve(__dirname, '../../../../');
|
2013-12-28 20:01:08 +04:00
|
|
|
|
|
|
|
pathConfig.should.have.property('appRoot', appRoot);
|
2016-01-11 14:37:59 +03:00
|
|
|
});
|
|
|
|
|
2014-02-08 19:41:15 +04:00
|
|
|
it('should allow specific properties to be user defined', function () {
|
2017-02-02 15:46:30 +03:00
|
|
|
var contentPath = path.join(configUtils.config.get('paths').appRoot, 'otherContent', '/');
|
2014-01-05 10:40:53 +04:00
|
|
|
|
2016-09-13 23:24:57 +03:00
|
|
|
configUtils.set('paths:contentPath', contentPath);
|
2017-02-02 15:46:30 +03:00
|
|
|
configUtils.config.get('paths').should.have.property('contentPath', contentPath);
|
|
|
|
configUtils.config.getContentPath('images').should.eql(contentPath + 'images/');
|
2013-12-28 20:01:08 +04:00
|
|
|
});
|
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-01-18 06:54:56 +03:00
|
|
|
describe('Storage', function () {
|
|
|
|
it('should default to local-file-store', function () {
|
2017-02-02 15:46:30 +03:00
|
|
|
configUtils.config.get('paths').should.have.property('internalStoragePath', path.join(configUtils.config.get('paths').corePath, '/server/storage/'));
|
2015-01-18 06:54:56 +03:00
|
|
|
|
2017-02-02 15:46:30 +03:00
|
|
|
configUtils.config.get('storage').should.have.property('active', {
|
2016-08-22 20:55:28 +03:00
|
|
|
images: 'local-file-store',
|
|
|
|
themes: 'local-file-store'
|
|
|
|
});
|
2015-01-18 06:54:56 +03:00
|
|
|
});
|
|
|
|
|
2016-09-13 22:47:36 +03:00
|
|
|
it('no effect: setting a custom active storage as string', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2015-01-18 06:54:56 +03:00
|
|
|
storage: {
|
|
|
|
active: 's3',
|
|
|
|
s3: {}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-02 15:46:30 +03:00
|
|
|
configUtils.config.get('storage').should.have.property('active', 's3');
|
|
|
|
configUtils.config.get('storage').should.have.property('s3', {});
|
2015-01-18 06:54:56 +03:00
|
|
|
});
|
2016-08-22 20:55:28 +03:00
|
|
|
|
2016-09-13 22:47:36 +03:00
|
|
|
it('able to set storage for themes (but not officially supported!)', function () {
|
2016-08-22 20:55:28 +03:00
|
|
|
configUtils.set({
|
|
|
|
storage: {
|
|
|
|
active: {
|
2016-09-13 22:47:36 +03:00
|
|
|
images: 'local-file-store',
|
2016-08-22 20:55:28 +03:00
|
|
|
themes: 's3'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-02 15:46:30 +03:00
|
|
|
configUtils.config.get('storage').should.have.property('active', {
|
2016-08-22 20:55:28 +03:00
|
|
|
images: 'local-file-store',
|
2016-09-13 22:47:36 +03:00
|
|
|
themes: 's3'
|
2016-08-22 20:55:28 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow setting a custom active storage as object', function () {
|
|
|
|
configUtils.set({
|
|
|
|
storage: {
|
|
|
|
active: {
|
|
|
|
images: 's2',
|
2016-08-23 15:07:25 +03:00
|
|
|
themes: 'local-file-store'
|
2016-08-22 20:55:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-02 15:46:30 +03:00
|
|
|
configUtils.config.get('storage').should.have.property('active', {
|
2016-08-22 20:55:28 +03:00
|
|
|
images: 's2',
|
2016-08-23 15:07:25 +03:00
|
|
|
themes: 'local-file-store'
|
2016-08-22 20:55:28 +03:00
|
|
|
});
|
|
|
|
});
|
2015-01-18 06:54:56 +03:00
|
|
|
});
|
2014-09-10 08:06:24 +04:00
|
|
|
});
|