Skip to content

fix: Double value for a flag converted to integer #442

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

Merged
merged 2 commits into from
Sep 21, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ private <T> T convertValue(Object value, Class<?> expectedType) {
|| expectedType == Double.class;

if (isPrimitive) {
if (value.getClass() == Integer.class && expectedType == Double.class) {
return (T) Double.valueOf((Integer) value);
}
return (T) value;
}
return (T) objectToValue(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,24 @@ void should_resolve_a_valid_double_flag_with_TARGETING_MATCH_reason() {
assertEquals(want, got);
}

@SneakyThrows
@Test
void should_resolve_a_valid_double_flag_with_TARGETING_MATCH_reason_if_value_point_zero() {
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<Double> got = client.getDoubleDetails("double_point_zero_key", 200.20, this.evaluationContext);
FlagEvaluationDetails<Double> want = FlagEvaluationDetails.<Double>builder()
.value(100.0)
.reason(Reason.TARGETING_MATCH.name())
.variant("True")
.flagMetadata(defaultMetadata)
.flagKey("double_point_zero_key")
.build();
assertEquals(want, got);
}

@SneakyThrows
@Test
void should_use_double_default_value_if_the_flag_is_disabled() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"trackEvents": true,
"variationType": "True",
"failed": false,
"version": 0,
"reason": "TARGETING_MATCH",
"errorCode": "",
"value": 100 ,
"metadata": {
"pr_link": "https://github.com/thomaspoignant/go-feature-flag/pull/916",
"version": 1
}
}