Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions libs/providers/flagd/src/e2e/step-definitions/providerSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FlagdContainer } from '../tests/flagdContainer';
import type { State, Steps } from './state';
import { FlagdProvider } from '../../lib/flagd-provider';
import type { FlagdProviderOptions } from '../../lib/configuration';
import { ProviderStatus } from '@openfeature/server-sdk';

export const providerSteps: Steps =
(state: State) =>
Expand Down Expand Up @@ -67,6 +68,21 @@ export const providerSteps: Steps =
state.providerType = providerType;
});

function mapProviderState(state: string): ProviderStatus {
const mappedState = state.toUpperCase().replace('-', '_');
const status = Object.values(ProviderStatus).find((s) => s === mappedState);

if (!status) {
throw new Error(`Unknown provider status: ${state}`);
}

return status;
}

then(/^the client should be in (.*) state/, (providerState: string) => {
expect(state.client?.providerStatus).toBe(mapProviderState(providerState));
});

when(/^the connection is lost for (\d+)s$/, async (time) => {
console.log('stopping flagd');
await fetch('http://' + container.getLaunchpadUrl() + '/restart?seconds=' + time);
Expand Down
2 changes: 2 additions & 0 deletions libs/providers/flagd/src/e2e/step-definitions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export function mapValueToType(value: string, type: string): any {
return value.toLowerCase() as ResolverType;
case 'CacheType':
return value as CacheOption;
case 'StringList':
return value.split(',').map((item) => item.trim());
case 'Object':
if (value == 'null') {
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/flagd/src/e2e/tests/in-process.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('in-process', () => {
// remove filters as we add support for features
// see: https://github.com/open-feature/js-sdk-contrib/issues/1096 and child issues
tagFilter:
'@in-process and not @targetURI and not @customCert and not @events and not @sync and not @grace and not @metadata and not @contextEnrichment',
'@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',
scenarioNameTemplate: (vars) => {
return `${vars.scenarioTitle} (${vars.scenarioTags.join(',')} ${vars.featureTags.join(',')})`;
},
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/flagd/src/e2e/tests/rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('rpc', () => {
tagFilter:
// remove filters as we add support for features
// see: https://github.com/open-feature/js-sdk-contrib/issues/1096 and child issues
'@rpc and not @targetURI and not @customCert and not @events and not @stream and not @grace and not @metadata and not @contextEnrichment and not @caching',
'@rpc and not @targetURI and not @customCert and not @forbidden and not @events and not @stream and not @grace and not @metadata and not @contextEnrichment and not @caching',
scenarioNameTemplate: (vars) => {
return `${vars.scenarioTitle} (${vars.scenarioTags.join(',')} ${vars.featureTags.join(',')})`;
},
Expand Down
20 changes: 20 additions & 0 deletions libs/providers/flagd/src/lib/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ describe('Configuration', () => {
});
});

it('should use flagd sync port over flagd port environment option', () => {
const port = 8080;
const syncPort = 9090;

process.env['FLAGD_PORT'] = `${port}`;
process.env['FLAGD_SYNC_PORT'] = `${syncPort}`;

expect(getConfig()).toStrictEqual(
expect.objectContaining({
port: syncPort,
}),
);
});

it('should use incoming options over defaults and environment variable', () => {
const options: FlagdProviderOptions = {
host: 'test',
Expand All @@ -76,6 +90,7 @@ describe('Configuration', () => {

process.env['FLAGD_HOST'] = 'override';
process.env['FLAGD_PORT'] = '8080';
process.env['FLAGD_SYNC_PORT'] = '9090';
process.env['FLAGD_TLS'] = 'false';
process.env['FLAGD_DEFAULT_AUTHORITY'] = 'test-authority-override';

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

it('should ignore an invalid sync port set as an environment variable', () => {
process.env['FLAGD_SYNC_PORT'] = 'invalid number';
expect(getConfig()).toStrictEqual(expect.objectContaining({ port: 8013 }));
});

describe('port handling', () => {
describe('for "in-process" evaluation', () => {
const resolverType = 'in-process';
Expand Down
4 changes: 4 additions & 0 deletions libs/providers/flagd/src/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const DEFAULT_IN_PROCESS_CONFIG: Config = { ...DEFAULT_CONFIG, resolverType: 'in
enum ENV_VAR {
FLAGD_HOST = 'FLAGD_HOST',
FLAGD_PORT = 'FLAGD_PORT',
FLAGD_SYNC_PORT = 'FLAGD_SYNC_PORT',
FLAGD_DEADLINE_MS = 'FLAGD_DEADLINE_MS',
FLAGD_TLS = 'FLAGD_TLS',
FLAGD_SOCKET_PATH = 'FLAGD_SOCKET_PATH',
Expand Down Expand Up @@ -137,6 +138,9 @@ const getEnvVarConfig = (): Partial<Config> => {
...(Number(process.env[ENV_VAR.FLAGD_PORT]) && {
port: Number(process.env[ENV_VAR.FLAGD_PORT]),
}),
...(Number(process.env[ENV_VAR.FLAGD_SYNC_PORT]) && {
port: Number(process.env[ENV_VAR.FLAGD_SYNC_PORT]),
}),
...(Number(process.env[ENV_VAR.FLAGD_DEADLINE_MS]) && {
deadlineMs: Number(process.env[ENV_VAR.FLAGD_DEADLINE_MS]),
}),
Expand Down