mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-11 00:24:08 +00:00
test(cliproxy): pin routing strategy test env scope
This commit is contained in:
@@ -6,6 +6,8 @@ import * as path from 'path';
|
|||||||
describe('cliproxy routing strategy service', () => {
|
describe('cliproxy routing strategy service', () => {
|
||||||
let tempHome = '';
|
let tempHome = '';
|
||||||
let scopedConfigDir = '';
|
let scopedConfigDir = '';
|
||||||
|
let originalCcsDir: string | undefined;
|
||||||
|
let originalCcsHome: string | undefined;
|
||||||
let runWithScopedConfigDir: <T>(ccsDir: string, fn: () => Promise<T> | T) => Promise<T>;
|
let runWithScopedConfigDir: <T>(ccsDir: string, fn: () => Promise<T> | T) => Promise<T>;
|
||||||
let routingTarget = {
|
let routingTarget = {
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
@@ -18,6 +20,10 @@ describe('cliproxy routing strategy service', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-routing-strategy-'));
|
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-routing-strategy-'));
|
||||||
scopedConfigDir = path.join(tempHome, '.ccs');
|
scopedConfigDir = path.join(tempHome, '.ccs');
|
||||||
|
originalCcsDir = process.env.CCS_DIR;
|
||||||
|
originalCcsHome = process.env.CCS_HOME;
|
||||||
|
process.env.CCS_DIR = scopedConfigDir;
|
||||||
|
process.env.CCS_HOME = tempHome;
|
||||||
|
|
||||||
({ runWithScopedConfigDir } = await import('../../../src/utils/config-manager'));
|
({ runWithScopedConfigDir } = await import('../../../src/utils/config-manager'));
|
||||||
});
|
});
|
||||||
@@ -25,6 +31,18 @@ describe('cliproxy routing strategy service', () => {
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mock.restore();
|
mock.restore();
|
||||||
|
|
||||||
|
if (originalCcsDir !== undefined) {
|
||||||
|
process.env.CCS_DIR = originalCcsDir;
|
||||||
|
} else {
|
||||||
|
delete process.env.CCS_DIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originalCcsHome !== undefined) {
|
||||||
|
process.env.CCS_HOME = originalCcsHome;
|
||||||
|
} else {
|
||||||
|
delete process.env.CCS_HOME;
|
||||||
|
}
|
||||||
|
|
||||||
if (tempHome && fs.existsSync(tempHome)) {
|
if (tempHome && fs.existsSync(tempHome)) {
|
||||||
fs.rmSync(tempHome, { recursive: true, force: true });
|
fs.rmSync(tempHome, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user