-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathconfiguration.spec.ts
77 lines (67 loc) · 2.12 KB
/
configuration.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { FlagdProviderOptions, getConfig } from './configuration';
import { DEFAULT_MAX_CACHE_SIZE } from './constants';
describe('Configuration', () => {
const OLD_ENV = process.env;
beforeEach(() => {
jest.resetModules(); // Most important - it clears the cache
process.env = { ...OLD_ENV }; // Make a copy
});
it('should return the default values', () => {
expect(getConfig()).toStrictEqual({
host: 'localhost',
port: 8013,
tls: false,
maxCacheSize: DEFAULT_MAX_CACHE_SIZE,
cache: 'lru',
resolverType: 'rpc',
selector: '',
});
});
it('should override defaults with environment variables', () => {
const host = 'dev';
const port = 8080;
const tls = true;
const socketPath = '/tmp/flagd.socks';
const maxCacheSize = 333;
const cache = 'disabled';
const resolverType = 'in-process';
const selector = 'app=weather';
process.env['FLAGD_HOST'] = host;
process.env['FLAGD_PORT'] = `${port}`;
process.env['FLAGD_TLS'] = `${tls}`;
process.env['FLAGD_SOCKET_PATH'] = socketPath;
process.env['FLAGD_CACHE'] = cache;
process.env['FLAGD_MAX_CACHE_SIZE'] = `${maxCacheSize}`;
process.env['FLAGD_SOURCE_SELECTOR'] = `${selector}`;
process.env['FLAGD_RESOLVER'] = `${resolverType}`;
expect(getConfig()).toStrictEqual({
host,
port,
tls,
socketPath,
maxCacheSize,
cache,
resolverType,
selector,
});
});
it('should use incoming options over defaults and environment variable', () => {
const options: FlagdProviderOptions = {
host: 'test',
port: 3000,
tls: true,
maxCacheSize: 1000,
cache: 'lru',
resolverType: 'rpc',
selector: '',
};
process.env['FLAGD_HOST'] = 'override';
process.env['FLAGD_PORT'] = '8080';
process.env['FLAGD_TLS'] = 'false';
expect(getConfig(options)).toStrictEqual(options);
});
it('should ignore an valid port set as an environment variable', () => {
process.env['FLAGD_PORT'] = 'invalid number';
expect(getConfig()).toStrictEqual(expect.objectContaining({ port: 8013 }));
});
});