Skip to content

Commit 5baa605

Browse files
committed
test: add cases for ConfigLoader.loadFromGit
1 parent 7c2fe92 commit 5baa605

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

test/ConfigLoader.test.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ describe('ConfigLoader', () => {
253253
path: tempConfigFile,
254254
},
255255
],
256-
reloadIntervalSeconds: 0.001,
256+
reloadIntervalSeconds: 0.01,
257257
},
258258
};
259259

@@ -262,7 +262,7 @@ describe('ConfigLoader', () => {
262262
await configLoader.start();
263263

264264
// Make sure the reload interval is triggered
265-
await new Promise((resolve) => setTimeout(resolve, 100));
265+
await new Promise((resolve) => setTimeout(resolve, 50));
266266

267267
expect(spy.callCount).to.greaterThan(1);
268268
});
@@ -313,7 +313,7 @@ describe('ConfigLoader', () => {
313313
enabled: true,
314314
};
315315

316-
const config = await configLoader.loadFromGit(source);
316+
const config = await configLoader.loadFromSource(source);
317317

318318
// Verify the loaded config has expected structure
319319
expect(config).to.be.an('object');
@@ -331,7 +331,7 @@ describe('ConfigLoader', () => {
331331
};
332332

333333
try {
334-
await configLoader.loadFromGit(source);
334+
await configLoader.loadFromSource(source);
335335
throw new Error('Expected error was not thrown');
336336
} catch (error) {
337337
expect(error.message).to.equal('Invalid configuration file path in repository');
@@ -348,13 +348,48 @@ describe('ConfigLoader', () => {
348348
enabled: true,
349349
};
350350

351-
const config = await configLoader.loadFromHttp(source);
351+
const config = await configLoader.loadFromSource(source);
352352

353353
// Verify the loaded config has expected structure
354354
expect(config).to.be.an('object');
355355
expect(config).to.have.property('proxyUrl');
356356
expect(config).to.have.property('cookieSecret');
357357
});
358+
359+
it('should throw error if repository is invalid', async function () {
360+
const source = {
361+
type: 'git',
362+
repository: 'invalid-repository',
363+
path: 'proxy.config.json',
364+
branch: 'main',
365+
enabled: true,
366+
};
367+
368+
try {
369+
await configLoader.loadFromSource(source);
370+
throw new Error('Expected error was not thrown');
371+
} catch (error) {
372+
expect(error.message).to.equal('Invalid repository URL format');
373+
}
374+
});
375+
376+
it('should throw error if branch name is invalid', async function () {
377+
const source = {
378+
type: 'git',
379+
repository: 'https://github.com/finos/git-proxy.git',
380+
path: 'proxy.config.json',
381+
branch: '..', // invalid branch pattern
382+
enabled: true,
383+
};
384+
385+
try {
386+
await configLoader.loadFromSource(source);
387+
throw new Error('Expected error was not thrown');
388+
} catch (error) {
389+
expect(error.message).to.equal('Invalid branch name format');
390+
}
391+
});
392+
358393
});
359394

360395
describe('deepMerge', () => {

0 commit comments

Comments
 (0)