Skip to content

Commit

Permalink
fix: [go-feature-flag] Make flag metadata optional (#572)
Browse files Browse the repository at this point in the history
Signed-off-by: itchyny <[email protected]>
Co-authored-by: Thomas Poignant <[email protected]>
  • Loading branch information
itchyny and thomaspoignant authored Dec 7, 2023
1 parent 7fea4ec commit 6a70bc4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ private ErrorCode mapErrorCode(String errorCode) {
*/
private ImmutableMetadata convertFlagMetadata(Map<String, Object> flagMetadata) {
ImmutableMetadata.ImmutableMetadataBuilder builder = ImmutableMetadata.builder();
if (flagMetadata == null) {
return builder.build();
}
flagMetadata.forEach((k, v) -> {
if (v instanceof Long) {
builder.addLong(k, (Long) v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,23 @@ void should_not_fail_if_receive_an_unknown_field_in_response() {
assertEquals(want, got);
}

@SneakyThrows
@Test
void should_not_fail_if_no_metadata_in_response() {
GoFeatureFlagProvider g = new GoFeatureFlagProvider(GoFeatureFlagProviderOptions.builder().endpoint(this.baseUrl.toString()).timeout(1000).build());
String providerName = this.testName;
OpenFeatureAPI.getInstance().setProviderAndWait(providerName, g);
Client client = OpenFeatureAPI.getInstance().getClient(providerName);
FlagEvaluationDetails<Boolean> got = client.getBooleanDetails("no_metadata",false, this.evaluationContext);
FlagEvaluationDetails<Boolean> want = FlagEvaluationDetails.<Boolean>builder()
.value(true)
.variant("True")
.flagKey("no_metadata")
.reason(Reason.TARGETING_MATCH.name())
.build();
assertEquals(want, got);
}

@SneakyThrows
@Test
void should_publish_events() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"trackEvents": true,
"variationType": "True",
"failed": false,
"version": 0,
"reason": "TARGETING_MATCH",
"errorCode": "",
"value": true
}

0 comments on commit 6a70bc4

Please sign in to comment.