2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
2021-06-18 23:19:16 +03:00
|
|
|
const _ = require('lodash');
|
2020-06-02 00:06:50 +03:00
|
|
|
const configUtils = require('../../../../core/shared/config/utils');
|
2016-10-18 11:04:44 +03:00
|
|
|
|
2021-06-18 23:19:16 +03:00
|
|
|
let fakeConfig = {};
|
|
|
|
let fakeNconf = {};
|
|
|
|
let changedKey = [];
|
|
|
|
|
2021-06-16 16:42:06 +03:00
|
|
|
describe('Config Utils', function () {
|
2016-10-18 11:04:44 +03:00
|
|
|
describe('makePathsAbsolute', function () {
|
2021-06-18 23:19:16 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
changedKey = [];
|
2020-04-29 18:44:27 +03:00
|
|
|
|
2021-06-18 23:19:16 +03:00
|
|
|
fakeNconf.get = (key) => {
|
|
|
|
key = key.replace(':', '');
|
|
|
|
return _.get(fakeConfig, key);
|
2020-04-29 18:44:27 +03:00
|
|
|
};
|
2021-06-18 23:19:16 +03:00
|
|
|
fakeNconf.set = function (key, value) {
|
2016-10-18 11:04:44 +03:00
|
|
|
changedKey.push([key, value]);
|
|
|
|
};
|
2021-06-18 23:19:16 +03:00
|
|
|
});
|
2016-10-18 11:04:44 +03:00
|
|
|
|
2021-06-18 23:19:16 +03:00
|
|
|
it('ensure we change paths only', function () {
|
|
|
|
fakeConfig.database = {
|
|
|
|
client: 'mysql',
|
|
|
|
connection: {
|
|
|
|
filename: 'content/data/ghost.db'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
configUtils.makePathsAbsolute(fakeNconf, fakeConfig.database, 'database');
|
2016-10-18 11:04:44 +03:00
|
|
|
|
|
|
|
changedKey.length.should.eql(1);
|
|
|
|
changedKey[0][0].should.eql('database:connection:filename');
|
|
|
|
changedKey[0][1].should.not.eql('content/data/ghost.db');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ensure it skips non strings', function () {
|
2021-06-18 23:19:16 +03:00
|
|
|
fakeConfig.database = {
|
|
|
|
test: 10
|
2020-04-29 18:44:27 +03:00
|
|
|
};
|
2016-10-18 11:04:44 +03:00
|
|
|
|
2021-06-18 23:19:16 +03:00
|
|
|
configUtils.makePathsAbsolute(fakeNconf, fakeConfig.database, 'database');
|
2016-10-18 11:04:44 +03:00
|
|
|
changedKey.length.should.eql(0);
|
|
|
|
});
|
|
|
|
|
2017-07-06 01:04:18 +03:00
|
|
|
it('ensure we don\'t change absolute paths', function () {
|
2021-06-18 23:19:16 +03:00
|
|
|
fakeConfig.database = {
|
|
|
|
client: 'mysql',
|
|
|
|
connection: {
|
|
|
|
filename: '/content/data/ghost.db'
|
2020-04-29 18:44:27 +03:00
|
|
|
}
|
|
|
|
};
|
2016-10-18 11:04:44 +03:00
|
|
|
|
2021-06-18 23:19:16 +03:00
|
|
|
configUtils.makePathsAbsolute(fakeNconf, fakeConfig.database, 'database');
|
2016-10-18 11:04:44 +03:00
|
|
|
changedKey.length.should.eql(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('match paths on windows', function () {
|
2021-06-18 23:19:16 +03:00
|
|
|
fakeConfig.database = {
|
|
|
|
filename: 'content\\data\\ghost.db'
|
2020-04-29 18:44:27 +03:00
|
|
|
|
2016-10-18 11:04:44 +03:00
|
|
|
};
|
|
|
|
|
2021-06-18 23:19:16 +03:00
|
|
|
configUtils.makePathsAbsolute(fakeNconf, fakeConfig.database, 'database');
|
2016-10-18 11:04:44 +03:00
|
|
|
changedKey.length.should.eql(1);
|
|
|
|
changedKey[0][0].should.eql('database:filename');
|
|
|
|
changedKey[0][1].should.not.eql('content\\data\\ghost.db');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|