Skip to content

Commit 033832e

Browse files
committed
Use flagd sync port over flagd port
Signed-off-by: marcozabel <[email protected]>
1 parent bfb10a3 commit 033832e

File tree

6 files changed

+43
-2
lines changed

6 files changed

+43
-2
lines changed

libs/providers/flagd/src/e2e/step-definitions/providerSteps.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FlagdContainer } from '../tests/flagdContainer';
33
import type { State, Steps } from './state';
44
import { FlagdProvider } from '../../lib/flagd-provider';
55
import type { FlagdProviderOptions } from '../../lib/configuration';
6+
import { ProviderStatus } from '@openfeature/server-sdk';
67

78
export const providerSteps: Steps =
89
(state: State) =>
@@ -67,6 +68,20 @@ export const providerSteps: Steps =
6768
state.providerType = providerType;
6869
});
6970

71+
function mapProviderState(state: string): ProviderStatus {
72+
const key = state.toUpperCase().replace('-', '_') as keyof typeof ProviderStatus;
73+
74+
if (!(key in ProviderStatus)) {
75+
throw new Error('Unknown provider status');
76+
}
77+
78+
return ProviderStatus[key];
79+
}
80+
81+
then(/^the client should be in (.*) state/, (providerState: string) => {
82+
expect(state.client?.providerStatus).toBe(mapProviderState(providerState));
83+
});
84+
7085
when(/^the connection is lost for (\d+)s$/, async (time) => {
7186
console.log('stopping flagd');
7287
await fetch('http://' + container.getLaunchpadUrl() + '/restart?seconds=' + time);

libs/providers/flagd/src/e2e/step-definitions/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export function mapValueToType(value: string, type: string): any {
1919
return value.toLowerCase() as ResolverType;
2020
case 'CacheType':
2121
return value as CacheOption;
22+
case 'StringList':
23+
return value.split(',').map((item) => item.trim());
2224
case 'Object':
2325
if (value == 'null') {
2426
return undefined;

libs/providers/flagd/src/e2e/tests/in-process.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('in-process', () => {
2222
// remove filters as we add support for features
2323
// see: https://github.com/open-feature/js-sdk-contrib/issues/1096 and child issues
2424
tagFilter:
25-
'@in-process and not @targetURI and not @customCert and not @events and not @sync and not @grace and not @metadata and not @contextEnrichment',
25+
'@in-process and not @targetURI and not @forbidden and not @customCert and not @events and not @sync and not @grace and not @metadata and not @unixsocket and not @sync-payload and not @contextEnrichment',
2626
scenarioNameTemplate: (vars) => {
2727
return `${vars.scenarioTitle} (${vars.scenarioTags.join(',')} ${vars.featureTags.join(',')})`;
2828
},

libs/providers/flagd/src/lib/configuration.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ describe('Configuration', () => {
6161
});
6262
});
6363

64+
it('should use flagd sync port over flagd port environment option', () => {
65+
const port = 8080;
66+
const syncPort = 9090;
67+
68+
process.env['FLAGD_PORT'] = `${port}`;
69+
process.env['FLAGD_SYNC_PORT'] = `${syncPort}`;
70+
71+
expect(getConfig()).toStrictEqual(
72+
expect.objectContaining({
73+
port: syncPort,
74+
}),
75+
);
76+
});
77+
6478
it('should use incoming options over defaults and environment variable', () => {
6579
const options: FlagdProviderOptions = {
6680
host: 'test',
@@ -76,6 +90,7 @@ describe('Configuration', () => {
7690

7791
process.env['FLAGD_HOST'] = 'override';
7892
process.env['FLAGD_PORT'] = '8080';
93+
process.env['FLAGD_SYNC_PORT'] = '9090';
7994
process.env['FLAGD_TLS'] = 'false';
8095
process.env['FLAGD_DEFAULT_AUTHORITY'] = 'test-authority-override';
8196

@@ -87,6 +102,11 @@ describe('Configuration', () => {
87102
expect(getConfig()).toStrictEqual(expect.objectContaining({ port: 8013 }));
88103
});
89104

105+
it('should ignore an valid sync port set as an environment variable', () => {
106+
process.env['FLAGD_SYNC_PORT'] = 'invalid number';
107+
expect(getConfig()).toStrictEqual(expect.objectContaining({ port: 8013 }));
108+
});
109+
90110
describe('port handling', () => {
91111
describe('for "in-process" evaluation', () => {
92112
const resolverType = 'in-process';

libs/providers/flagd/src/lib/configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const DEFAULT_IN_PROCESS_CONFIG: Config = { ...DEFAULT_CONFIG, resolverType: 'in
101101
enum ENV_VAR {
102102
FLAGD_HOST = 'FLAGD_HOST',
103103
FLAGD_PORT = 'FLAGD_PORT',
104+
FLAGD_SYNC_PORT = 'FLAGD_SYNC_PORT',
104105
FLAGD_DEADLINE_MS = 'FLAGD_DEADLINE_MS',
105106
FLAGD_TLS = 'FLAGD_TLS',
106107
FLAGD_SOCKET_PATH = 'FLAGD_SOCKET_PATH',
@@ -137,6 +138,9 @@ const getEnvVarConfig = (): Partial<Config> => {
137138
...(Number(process.env[ENV_VAR.FLAGD_PORT]) && {
138139
port: Number(process.env[ENV_VAR.FLAGD_PORT]),
139140
}),
141+
...(Number(process.env[ENV_VAR.FLAGD_SYNC_PORT]) && {
142+
port: Number(process.env[ENV_VAR.FLAGD_SYNC_PORT]),
143+
}),
140144
...(Number(process.env[ENV_VAR.FLAGD_DEADLINE_MS]) && {
141145
deadlineMs: Number(process.env[ENV_VAR.FLAGD_DEADLINE_MS]),
142146
}),

0 commit comments

Comments
 (0)