fix: merge eval context (#149)
fix merge eval context Signed-off-by: Robert Grassian <robert.grassian@split.io> Signed-off-by: Robert Grassian <robert.grassian@split.io>
This commit is contained in:
parent
54fbf081ed
commit
fad0f35fc8
|
|
@ -118,7 +118,7 @@ public class OpenFeatureClient implements Client {
|
|||
apiContext = openfeatureApi.getEvaluationContext() != null
|
||||
? openfeatureApi.getEvaluationContext()
|
||||
: new MutableContext();
|
||||
clientContext = openfeatureApi.getEvaluationContext() != null
|
||||
clientContext = this.getEvaluationContext() != null
|
||||
? this.getEvaluationContext()
|
||||
: new MutableContext();
|
||||
|
||||
|
|
|
|||
|
|
@ -29,4 +29,30 @@ class OpenFeatureClientTest implements HookFixtures {
|
|||
assertThat(actual.getValue()).isTrue();
|
||||
assertThat(TEST_LOGGER.getLoggingEvents()).filteredOn(event -> event.getLevel().equals(Level.ERROR)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void mergeContextTest() {
|
||||
TEST_LOGGER.clear();
|
||||
|
||||
String flag = "feature key";
|
||||
boolean defaultValue = false;
|
||||
String targetingKey = "targeting key";
|
||||
EvaluationContext ctx = new MutableContext(targetingKey);
|
||||
|
||||
OpenFeatureAPI api = mock(OpenFeatureAPI.class);
|
||||
FeatureProvider mockProvider = mock(FeatureProvider.class);
|
||||
// this makes it so that true is returned only if the targeting key set at the client level is honored
|
||||
when(mockProvider.getBooleanEvaluation(
|
||||
eq(flag), eq(defaultValue), argThat(
|
||||
context -> context.getTargetingKey().equals(targetingKey)))).thenReturn(ProviderEvaluation.<Boolean>builder()
|
||||
.value(true).build());
|
||||
when(api.getProvider()).thenReturn(mockProvider);
|
||||
|
||||
OpenFeatureClient client = new OpenFeatureClient(api, "name", "version");
|
||||
client.setEvaluationContext(ctx);
|
||||
|
||||
FlagEvaluationDetails<Boolean> result = client.getBooleanDetails(flag, defaultValue);
|
||||
|
||||
assertThat(result.getValue()).isTrue();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue