|
1 | | -import { FlagdProviderOptions, getConfig } from './configuration'; |
| 1 | +import { Config, FlagdProviderOptions, getConfig } from './configuration'; |
2 | 2 | import { DEFAULT_MAX_CACHE_SIZE } from './constants'; |
3 | 3 |
|
4 | 4 | describe('Configuration', () => { |
@@ -77,4 +77,41 @@ describe('Configuration', () => { |
77 | 77 | process.env['FLAGD_PORT'] = 'invalid number'; |
78 | 78 | expect(getConfig()).toStrictEqual(expect.objectContaining({ port: 8013 })); |
79 | 79 | }); |
| 80 | + |
| 81 | + describe('port handling', () => { |
| 82 | + describe('for "in-process" evaluation', () => { |
| 83 | + const resolverType = 'in-process'; |
| 84 | + const port = 8015; |
| 85 | + it('should use default in-process port if resolver type is set per envVar and no port is provided', () => { |
| 86 | + process.env['FLAGD_RESOLVER'] = resolverType; |
| 87 | + expect(getConfig()).toStrictEqual(expect.objectContaining({ port, resolverType })); |
| 88 | + }); |
| 89 | + it('should use default in-process port if resolver type is set per options and no port is provided', () => { |
| 90 | + const options: Partial<Config> = { resolverType }; |
| 91 | + expect(getConfig(options)).toStrictEqual(expect.objectContaining({ port, resolverType })); |
| 92 | + }); |
| 93 | + it('should use provided port if resolver type is set per options and port', () => { |
| 94 | + const port = 1111; |
| 95 | + const options: Partial<Config> = { resolverType, port }; |
| 96 | + expect(getConfig(options)).toStrictEqual(expect.objectContaining({ port, resolverType })); |
| 97 | + }); |
| 98 | + }); |
| 99 | + describe('for "rpc" evaluation', () => { |
| 100 | + const resolverType = 'rpc'; |
| 101 | + const port = 8013; |
| 102 | + it('should use default in-process port if resolver type is set per envVar and no port is provided', () => { |
| 103 | + process.env['FLAGD_RESOLVER'] = resolverType; |
| 104 | + expect(getConfig()).toStrictEqual(expect.objectContaining({ port, resolverType })); |
| 105 | + }); |
| 106 | + it('should use default in-process port if resolver type is set per options and no port is provided', () => { |
| 107 | + const options: Partial<Config> = { resolverType }; |
| 108 | + expect(getConfig(options)).toStrictEqual(expect.objectContaining({ port, resolverType })); |
| 109 | + }); |
| 110 | + it('should use provided port if resolver type is set per options and port', () => { |
| 111 | + const port = 1111; |
| 112 | + const options: Partial<Config> = { resolverType, port }; |
| 113 | + expect(getConfig(options)).toStrictEqual(expect.objectContaining({ port, resolverType })); |
| 114 | + }); |
| 115 | + }); |
| 116 | + }); |
80 | 117 | }); |
0 commit comments