Skip to content

Commit

Permalink
fix: [GO Feature Flag server] Implement ProviderStatus (#493)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
Signed-off-by: Thomas Poignant <[email protected]>
Co-authored-by: Michael Beemer <[email protected]>
  • Loading branch information
thomaspoignant and beeme1mr authored Jul 27, 2023
1 parent 6f0fafe commit e11269d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ErrorCode,
FlagNotFoundError,
OpenFeature,
ProviderStatus,
ResolutionDetails,
StandardResolutionReasons,
TypeMismatchError
Expand Down Expand Up @@ -59,7 +60,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 +74,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 +88,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 +104,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 +120,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 +172,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 +198,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 +301,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 +395,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 +487,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,8 @@ export class GoFeatureFlagProvider implements Provider {
// logger is the Open Feature logger to use
private logger?: Logger;

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 +99,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

0 comments on commit e11269d

Please sign in to comment.