tests: Add tests for `settings.json` parsing
parent
de0a450aec
commit
6c2f31a5cb
|
@ -825,5 +825,9 @@ exports.reloadSettings = () => {
|
|||
console.log(`Random string used for versioning assets: ${exports.randomVersionString}`);
|
||||
};
|
||||
|
||||
exports.exportedForTestingOnly = {
|
||||
parseSettings,
|
||||
};
|
||||
|
||||
// initially load settings
|
||||
exports.reloadSettings();
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
'use strict';
|
||||
|
||||
const assert = require('assert').strict;
|
||||
const {parseSettings} = require('../../../node/utils/Settings').exportedForTestingOnly;
|
||||
const path = require('path');
|
||||
const process = require('process');
|
||||
|
||||
describe(__filename, function () {
|
||||
describe('parseSettings', function () {
|
||||
let settings;
|
||||
const envVarSubstTestCases = [
|
||||
{name: 'true', val: 'true', var: 'SET_VAR_TRUE', want: true},
|
||||
{name: 'false', val: 'false', var: 'SET_VAR_FALSE', want: false},
|
||||
{name: 'null', val: 'null', var: 'SET_VAR_NULL', want: null},
|
||||
{name: 'undefined', val: 'undefined', var: 'SET_VAR_UNDEFINED', want: undefined},
|
||||
{name: 'number', val: '123', var: 'SET_VAR_NUMBER', want: 123},
|
||||
{name: 'string', val: 'foo', var: 'SET_VAR_STRING', want: 'foo'},
|
||||
{name: 'empty string', val: '', var: 'SET_VAR_EMPTY_STRING', want: ''},
|
||||
];
|
||||
|
||||
before(async function () {
|
||||
for (const tc of envVarSubstTestCases) process.env[tc.var] = tc.val;
|
||||
delete process.env.UNSET_VAR;
|
||||
settings = parseSettings(path.join(__dirname, 'settings.json'), true);
|
||||
assert(settings != null);
|
||||
});
|
||||
|
||||
describe('environment variable substitution', function () {
|
||||
describe('set', function () {
|
||||
for (const tc of envVarSubstTestCases) {
|
||||
it(tc.name, async function () {
|
||||
const obj = settings['environment variable substitution'].set;
|
||||
if (tc.name === 'undefined') {
|
||||
assert(!(tc.name in obj));
|
||||
} else {
|
||||
assert.equal(obj[tc.name], tc.want);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('unset', function () {
|
||||
it('no default', async function () {
|
||||
const obj = settings['environment variable substitution'].unset;
|
||||
assert.equal(obj['no default'], null);
|
||||
});
|
||||
|
||||
for (const tc of envVarSubstTestCases) {
|
||||
it(tc.name, async function () {
|
||||
const obj = settings['environment variable substitution'].unset;
|
||||
if (tc.name === 'undefined') {
|
||||
assert(!(tc.name in obj));
|
||||
} else {
|
||||
assert.equal(obj[tc.name], tc.want);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,39 @@
|
|||
// line comment
|
||||
/*
|
||||
* block comment
|
||||
*/
|
||||
{
|
||||
"trailing commas": {
|
||||
"lists": {
|
||||
"multiple lines": [
|
||||
"",
|
||||
]
|
||||
},
|
||||
"objects": {
|
||||
"multiple lines": {
|
||||
"key": "",
|
||||
}
|
||||
}
|
||||
},
|
||||
"environment variable substitution": {
|
||||
"set": {
|
||||
"true": "${SET_VAR_TRUE}",
|
||||
"false": "${SET_VAR_FALSE}",
|
||||
"null": "${SET_VAR_NULL}",
|
||||
"undefined": "${SET_VAR_UNDEFINED}",
|
||||
"number": "${SET_VAR_NUMBER}",
|
||||
"string": "${SET_VAR_STRING}",
|
||||
"empty string": "${SET_VAR_EMPTY_STRING}"
|
||||
},
|
||||
"unset": {
|
||||
"no default": "${UNSET_VAR}",
|
||||
"true": "${UNSET_VAR:true}",
|
||||
"false": "${UNSET_VAR:false}",
|
||||
"null": "${UNSET_VAR:null}",
|
||||
"undefined": "${UNSET_VAR:undefined}",
|
||||
"number": "${UNSET_VAR:123}",
|
||||
"string": "${UNSET_VAR:foo}",
|
||||
"empty string": "${UNSET_VAR:}"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue