Some checks failed
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
81 lines
2.1 KiB
TypeScript
81 lines
2.1 KiB
TypeScript
import type { GlobalConfig } from '@n8n/config';
|
|
|
|
import { resolveHealthEndpointPath } from '@/utils/health-endpoint.util';
|
|
|
|
describe('resolveHealthEndpointPath', () => {
|
|
let mockGlobalConfig: GlobalConfig;
|
|
let originalEnv: NodeJS.ProcessEnv;
|
|
|
|
beforeEach(() => {
|
|
originalEnv = { ...process.env };
|
|
|
|
mockGlobalConfig = {
|
|
path: '/',
|
|
endpoints: {
|
|
health: '/healthz',
|
|
},
|
|
} as GlobalConfig;
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = originalEnv;
|
|
});
|
|
|
|
it('should return default health endpoint when N8N_PATH is /', () => {
|
|
mockGlobalConfig.path = '/';
|
|
delete process.env.N8N_ENDPOINT_HEALTH;
|
|
|
|
const result = resolveHealthEndpointPath(mockGlobalConfig);
|
|
|
|
expect(result).toBe('/healthz');
|
|
});
|
|
|
|
it('should combine N8N_PATH with health endpoint when N8N_PATH is set', () => {
|
|
mockGlobalConfig.path = '/n8n';
|
|
delete process.env.N8N_ENDPOINT_HEALTH;
|
|
|
|
const result = resolveHealthEndpointPath(mockGlobalConfig);
|
|
|
|
expect(result).toBe('/n8n/healthz');
|
|
});
|
|
|
|
it('should prioritize N8N_ENDPOINT_HEALTH over N8N_PATH', () => {
|
|
mockGlobalConfig.path = '/n8n';
|
|
mockGlobalConfig.endpoints.health = '/custom/health';
|
|
process.env.N8N_ENDPOINT_HEALTH = '/custom/health';
|
|
|
|
const result = resolveHealthEndpointPath(mockGlobalConfig);
|
|
|
|
expect(result).toBe('/custom/health');
|
|
});
|
|
|
|
it('should use N8N_ENDPOINT_HEALTH even when it is the default value', () => {
|
|
mockGlobalConfig.path = '/n8n';
|
|
mockGlobalConfig.endpoints.health = '/healthz';
|
|
process.env.N8N_ENDPOINT_HEALTH = '/healthz';
|
|
|
|
const result = resolveHealthEndpointPath(mockGlobalConfig);
|
|
|
|
expect(result).toBe('/healthz');
|
|
});
|
|
|
|
it('should handle multiple path segments in N8N_PATH', () => {
|
|
mockGlobalConfig.path = '/api/n8n';
|
|
delete process.env.N8N_ENDPOINT_HEALTH;
|
|
|
|
const result = resolveHealthEndpointPath(mockGlobalConfig);
|
|
|
|
expect(result).toBe('/api/n8n/healthz');
|
|
});
|
|
|
|
it('should handle custom health endpoint with N8N_PATH', () => {
|
|
mockGlobalConfig.path = '/n8n';
|
|
mockGlobalConfig.endpoints.health = '/health/check';
|
|
delete process.env.N8N_ENDPOINT_HEALTH;
|
|
|
|
const result = resolveHealthEndpointPath(mockGlobalConfig);
|
|
|
|
expect(result).toBe('/n8n/health/check');
|
|
});
|
|
});
|