2024-10-03 21:28:36 +02:00
|
|
|
import { ConfigRepository } from 'src/repositories/config.repository';
|
|
|
|
|
2024-10-03 22:58:15 +02:00
|
|
|
const getEnv = () => new ConfigRepository().getEnv();
|
2024-05-17 15:44:30 +02:00
|
|
|
|
2024-10-03 22:58:15 +02:00
|
|
|
describe('getEnv', () => {
|
2024-05-17 15:44:30 +02:00
|
|
|
beforeEach(() => {
|
2024-10-03 22:58:15 +02:00
|
|
|
delete process.env.IMMICH_WORKERS_INCLUDE;
|
|
|
|
delete process.env.IMMICH_WORKERS_EXCLUDE;
|
|
|
|
delete process.env.NO_COLOR;
|
2024-05-17 15:44:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return default workers', () => {
|
2024-10-03 22:58:15 +02:00
|
|
|
const { workers } = getEnv();
|
|
|
|
expect(workers).toEqual(['api', 'microservices']);
|
2024-05-17 15:44:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return included workers', () => {
|
|
|
|
process.env.IMMICH_WORKERS_INCLUDE = 'api';
|
2024-10-03 22:58:15 +02:00
|
|
|
const { workers } = getEnv();
|
|
|
|
expect(workers).toEqual(['api']);
|
2024-05-17 15:44:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should excluded workers from defaults', () => {
|
|
|
|
process.env.IMMICH_WORKERS_EXCLUDE = 'api';
|
2024-10-03 22:58:15 +02:00
|
|
|
const { workers } = getEnv();
|
|
|
|
expect(workers).toEqual(['microservices']);
|
2024-05-17 15:44:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should exclude workers from include list', () => {
|
|
|
|
process.env.IMMICH_WORKERS_INCLUDE = 'api,microservices,randomservice';
|
|
|
|
process.env.IMMICH_WORKERS_EXCLUDE = 'randomservice,microservices';
|
2024-10-03 22:58:15 +02:00
|
|
|
const { workers } = getEnv();
|
|
|
|
expect(workers).toEqual(['api']);
|
2024-05-17 15:44:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove whitespace from included workers before parsing', () => {
|
|
|
|
process.env.IMMICH_WORKERS_INCLUDE = 'api, microservices';
|
2024-10-03 22:58:15 +02:00
|
|
|
const { workers } = getEnv();
|
|
|
|
expect(workers).toEqual(['api', 'microservices']);
|
2024-05-17 15:44:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove whitespace from excluded workers before parsing', () => {
|
|
|
|
process.env.IMMICH_WORKERS_EXCLUDE = 'api, microservices';
|
2024-10-03 22:58:15 +02:00
|
|
|
const { workers } = getEnv();
|
|
|
|
expect(workers).toEqual([]);
|
2024-05-17 15:44:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove whitespace from included and excluded workers before parsing', () => {
|
|
|
|
process.env.IMMICH_WORKERS_INCLUDE = 'api, microservices, randomservice,randomservice2';
|
|
|
|
process.env.IMMICH_WORKERS_EXCLUDE = 'randomservice,microservices, randomservice2';
|
2024-10-03 22:58:15 +02:00
|
|
|
const { workers } = getEnv();
|
|
|
|
expect(workers).toEqual(['api']);
|
2024-05-17 15:44:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw error for invalid workers', () => {
|
|
|
|
process.env.IMMICH_WORKERS_INCLUDE = 'api,microservices,randomservice';
|
2024-10-03 22:58:15 +02:00
|
|
|
expect(getEnv).toThrowError('Invalid worker(s) found: api,microservices,randomservice');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should default noColor to false', () => {
|
|
|
|
const { noColor } = getEnv();
|
|
|
|
expect(noColor).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map NO_COLOR=1 to true', () => {
|
|
|
|
process.env.NO_COLOR = '1';
|
|
|
|
const { noColor } = getEnv();
|
|
|
|
expect(noColor).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map NO_COLOR=true to true', () => {
|
|
|
|
process.env.NO_COLOR = 'true';
|
|
|
|
const { noColor } = getEnv();
|
|
|
|
expect(noColor).toBe(true);
|
2024-05-17 15:44:30 +02:00
|
|
|
});
|
|
|
|
});
|