Skip to content

Commit ba40989

Browse files
committed
test: increase test coverage for config
1 parent 499570c commit ba40989

1 file changed

Lines changed: 73 additions & 1 deletion

File tree

test/testConfig.test.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ describe('user configuration', function () {
371371
expect(firstAuth.type).to.equal('ldap');
372372
});
373373

374-
375374
afterEach(function () {
376375
fs.rmSync(tempUserFile);
377376
fs.rmdirSync(tempDir);
@@ -404,3 +403,76 @@ describe('validate config files', function () {
404403
delete require.cache[require.resolve('../src/config')];
405404
});
406405
});
406+
407+
describe('Configuration Update Handling', function () {
408+
let tempDir;
409+
let tempUserFile;
410+
let oldEnv;
411+
412+
beforeEach(function () {
413+
delete require.cache[require.resolve('../src/config')];
414+
oldEnv = { ...process.env };
415+
tempDir = fs.mkdtempSync('gitproxy-test');
416+
tempUserFile = path.join(tempDir, 'test-settings.json');
417+
require('../src/config/file').configFile = tempUserFile;
418+
});
419+
420+
it('should test ConfigLoader initialization', function () {
421+
const configWithSources = {
422+
configurationSources: {
423+
enabled: true,
424+
sources: [
425+
{
426+
type: 'file',
427+
enabled: true,
428+
path: tempUserFile,
429+
},
430+
],
431+
},
432+
};
433+
434+
fs.writeFileSync(tempUserFile, JSON.stringify(configWithSources));
435+
436+
const config = require('../src/config');
437+
config.invalidateCache();
438+
439+
expect(() => config.getAuthorisedList()).to.not.throw();
440+
});
441+
442+
it('should handle config loader initialization errors', function () {
443+
const invalidConfigSources = {
444+
configurationSources: {
445+
enabled: true,
446+
sources: [
447+
{
448+
type: 'invalid-type',
449+
enabled: true,
450+
path: tempUserFile,
451+
},
452+
],
453+
},
454+
};
455+
456+
fs.writeFileSync(tempUserFile, JSON.stringify(invalidConfigSources));
457+
458+
const consoleErrorSpy = require('sinon').spy(console, 'error');
459+
460+
const config = require('../src/config');
461+
config.invalidateCache();
462+
463+
expect(() => config.getAuthorisedList()).to.not.throw();
464+
465+
consoleErrorSpy.restore();
466+
});
467+
468+
afterEach(function () {
469+
if (fs.existsSync(tempUserFile)) {
470+
fs.rmSync(tempUserFile, { force: true });
471+
}
472+
if (fs.existsSync(tempDir)) {
473+
fs.rmdirSync(tempDir);
474+
}
475+
process.env = oldEnv;
476+
delete require.cache[require.resolve('../src/config')];
477+
});
478+
});

0 commit comments

Comments
 (0)