11package dev .openfeature .contrib .providers .gofeatureflag ;
22
3- import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
4- import static org .junit .jupiter .api .Assertions .assertEquals ;
5- import static org .junit .jupiter .api .Assertions .assertThrows ;
6-
73import java .io .IOException ;
84import java .nio .file .Files ;
95import java .nio .file .Paths ;
3329import okhttp3 .mockwebserver .MockWebServer ;
3430import okhttp3 .mockwebserver .RecordedRequest ;
3531
32+ import static org .junit .jupiter .api .Assertions .*;
33+
3634class GoFeatureFlagProviderTest {
3735 // Dispatcher is the configuration of the mock server to test the provider.
3836 final Dispatcher dispatcher = new Dispatcher () {
@@ -138,15 +136,17 @@ void should_resolve_a_valid_boolean_flag_with_TARGETING_MATCH_reason() throws In
138136 GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
139137 ProviderEvaluation <Boolean > res = g .getBooleanEvaluation ("bool_targeting_match" , false , this .evaluationContext );
140138 assertEquals (true , res .getValue ());
139+ assertNull (res .getErrorCode ());
141140 assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
142141 assertEquals ("True" , res .getVariant ());
143142 }
144143
145144 @ Test
146- void should_return_unknown_reason_if_not_exists_in_SDK () throws InvalidOptions {
145+ void should_return_custom_reason_if_returned_by_relay_proxy () throws InvalidOptions {
147146 GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
148147 ProviderEvaluation <Boolean > res = g .getBooleanEvaluation ("unknown_reason" , false , this .evaluationContext );
149148 assertEquals (true , res .getValue ());
149+ assertNull (res .getErrorCode ());
150150 assertEquals ("CUSTOM_REASON" , res .getReason ());
151151 assertEquals ("True" , res .getVariant ());
152152 }
@@ -170,6 +170,7 @@ void should_resolve_a_valid_string_flag_with_TARGETING_MATCH_reason() throws Inv
170170 GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
171171 ProviderEvaluation <String > res = g .getStringEvaluation ("string_key" , "defaultValue" , this .evaluationContext );
172172 assertEquals ("CC0000" , res .getValue ());
173+ assertNull (res .getErrorCode ());
173174 assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
174175 assertEquals ("True" , res .getVariant ());
175176 }
@@ -193,6 +194,7 @@ void should_resolve_a_valid_integer_flag_with_TARGETING_MATCH_reason() throws In
193194 GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
194195 ProviderEvaluation <Integer > res = g .getIntegerEvaluation ("integer_key" , 1200 , this .evaluationContext );
195196 assertEquals (100 , res .getValue ());
197+ assertNull (res .getErrorCode ());
196198 assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
197199 assertEquals ("True" , res .getVariant ());
198200 }
@@ -216,6 +218,7 @@ void should_resolve_a_valid_double_flag_with_TARGETING_MATCH_reason() throws Inv
216218 GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
217219 ProviderEvaluation <Double > res = g .getDoubleEvaluation ("double_key" , 1200.25 , this .evaluationContext );
218220 assertEquals (100.25 , res .getValue ());
221+ assertNull (res .getErrorCode ());
219222 assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
220223 assertEquals ("True" , res .getVariant ());
221224 }
@@ -234,6 +237,7 @@ void should_resolve_a_valid_value_flag_with_TARGETING_MATCH_reason() throws Inva
234237 ProviderEvaluation <Value > res = g .getObjectEvaluation ("object_key" , null , this .evaluationContext );
235238 Value want = new Value (new MutableStructure ().add ("test" , "test1" ).add ("test2" , false ).add ("test3" , 123.3 ).add ("test4" , 1 ));
236239 assertEquals (want , res .getValue ());
240+ assertNull (res .getErrorCode ());
237241 assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
238242 assertEquals ("True" , res .getVariant ());
239243 }
@@ -244,6 +248,7 @@ void should_wrap_into_value_if_wrong_type() throws InvalidOptions {
244248 ProviderEvaluation <Value > res = g .getObjectEvaluation ("string_key" , null , this .evaluationContext );
245249 Value want = new Value ("CC0000" );
246250 assertEquals (want , res .getValue ());
251+ assertNull (res .getErrorCode ());
247252 assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
248253 assertEquals ("True" , res .getVariant ());
249254 }
@@ -274,6 +279,7 @@ void should_throw_an_error_if_no_targeting_key() throws InvalidOptions {
274279 new Value ("false" ),
275280 new Value ("test3" ))));
276281 assertEquals (want , res .getValue ());
282+ assertNull (res .getErrorCode ());
277283 assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
278284 assertEquals ("True" , res .getVariant ());
279285 }
0 commit comments