Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [GO Feature Flag server] Implement ProviderStatus #493

Merged
merged 5 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
ErrorCode,
FlagNotFoundError,
OpenFeature,
OpenFeature, ProviderStatus,
thomaspoignant marked this conversation as resolved.
Show resolved Hide resolved
ResolutionDetails,
StandardResolutionReasons,
TypeMismatchError
Expand Down Expand Up @@ -59,7 +59,6 @@ describe('GoFeatureFlagProvider', () => {
const goff = new GoFeatureFlagProvider({endpoint});
expect(goff).toBeInstanceOf(GoFeatureFlagProvider);
});

it('should throw an error if proxy not ready', async () => {
const flagName = 'random-flag';
const targetingKey = 'user-key';
Expand All @@ -74,7 +73,6 @@ describe('GoFeatureFlagProvider', () => {
);
});
});

it('should throw an error if the call timeout', async () => {
const flagName = 'random-flag';
const targetingKey = 'user-key';
Expand All @@ -89,7 +87,6 @@ describe('GoFeatureFlagProvider', () => {
);
});
});

describe('error codes in HTTP response', () => {
it('SDK error codes should return correct code', async () => {
const flagName = 'random-other-flag';
Expand All @@ -106,7 +103,6 @@ describe('GoFeatureFlagProvider', () => {
expect(result.errorCode).toEqual(ErrorCode.PARSE_ERROR)
})
});

it('unknown error codes should return GENERAL code', async () => {
const flagName = 'random-other-other-flag';
const targetingKey = 'user-key';
Expand All @@ -123,7 +119,6 @@ describe('GoFeatureFlagProvider', () => {
})
});
});

it('should throw an error if we fail in other network errors case', async () => {
const flagName = 'random-flag';
const targetingKey = 'user-key';
Expand Down Expand Up @@ -176,7 +171,6 @@ describe('GoFeatureFlagProvider', () => {
);
});
});

it('should be valid with an API key provided', async () => {
const flagName = 'random-flag';
const targetingKey = 'user-key';
Expand All @@ -203,6 +197,14 @@ describe('GoFeatureFlagProvider', () => {
} as ResolutionDetails<boolean>);
});
});
it('provider should start not ready', async () => {
const goff = new GoFeatureFlagProvider({endpoint});
expect(goff.status).toEqual(ProviderStatus.NOT_READY);
});
it('provider should be ready after after setting the provider to Open Feature', async () => {
OpenFeature.setProvider( 'goff', goff);
expect(goff.status).toEqual(ProviderStatus.READY);
});
});

describe('resolveBooleanEvaluation', () => {
Expand Down Expand Up @@ -298,7 +300,6 @@ describe('GoFeatureFlagProvider', () => {
});
});
});

describe('resolveStringEvaluation', () => {
it('should throw an error if we expect a string and got another type', async () => {
const flagName = 'random-flag';
Expand Down Expand Up @@ -393,7 +394,6 @@ describe('GoFeatureFlagProvider', () => {
});
});
});

describe('resolveNumberEvaluation', () => {
it('should throw an error if we expect a number and got another type', async () => {
const flagName = 'random-flag';
Expand Down Expand Up @@ -486,7 +486,6 @@ describe('GoFeatureFlagProvider', () => {
});
});
});

describe('resolveObjectEvaluation', () => {
it('should throw an error if we expect a json array and got another type', async () => {
const flagName = 'random-flag';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
JsonValue,
Logger,
Provider,
ProviderStatus,
ResolutionDetails,
StandardResolutionReasons,
TypeMismatchError,
Expand Down Expand Up @@ -68,6 +69,9 @@ export class GoFeatureFlagProvider implements Provider {
// logger is the Open Feature logger to use
private logger?: Logger;

// status of the provider
thomaspoignant marked this conversation as resolved.
Show resolved Hide resolved
thomaspoignant marked this conversation as resolved.
Show resolved Hide resolved
private _status: ProviderStatus = ProviderStatus.NOT_READY;

constructor(options: GoFeatureFlagProviderOptions, logger?: Logger) {
this.timeout = options.timeout || 0; // default is 0 = no timeout
this.endpoint = options.endpoint;
Expand Down Expand Up @@ -96,6 +100,11 @@ export class GoFeatureFlagProvider implements Provider {
this.bgScheduler = setInterval(async () => await this.callGoffDataCollection(), this.dataFlushInterval)
this.dataCollectorBuffer = []
}
this._status = ProviderStatus.READY;
}

get status(){
return this._status;
}

/**
Expand Down