1
1
package dev .openfeature .contrib .providers .gofeatureflag ;
2
2
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
-
7
3
import java .io .IOException ;
8
4
import java .nio .file .Files ;
9
5
import java .nio .file .Paths ;
33
29
import okhttp3 .mockwebserver .MockWebServer ;
34
30
import okhttp3 .mockwebserver .RecordedRequest ;
35
31
32
+ import static org .junit .jupiter .api .Assertions .*;
33
+
36
34
class GoFeatureFlagProviderTest {
37
35
// Dispatcher is the configuration of the mock server to test the provider.
38
36
final Dispatcher dispatcher = new Dispatcher () {
@@ -138,15 +136,17 @@ void should_resolve_a_valid_boolean_flag_with_TARGETING_MATCH_reason() throws In
138
136
GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
139
137
ProviderEvaluation <Boolean > res = g .getBooleanEvaluation ("bool_targeting_match" , false , this .evaluationContext );
140
138
assertEquals (true , res .getValue ());
139
+ assertNull (res .getErrorCode ());
141
140
assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
142
141
assertEquals ("True" , res .getVariant ());
143
142
}
144
143
145
144
@ 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 {
147
146
GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
148
147
ProviderEvaluation <Boolean > res = g .getBooleanEvaluation ("unknown_reason" , false , this .evaluationContext );
149
148
assertEquals (true , res .getValue ());
149
+ assertNull (res .getErrorCode ());
150
150
assertEquals ("CUSTOM_REASON" , res .getReason ());
151
151
assertEquals ("True" , res .getVariant ());
152
152
}
@@ -170,6 +170,7 @@ void should_resolve_a_valid_string_flag_with_TARGETING_MATCH_reason() throws Inv
170
170
GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
171
171
ProviderEvaluation <String > res = g .getStringEvaluation ("string_key" , "defaultValue" , this .evaluationContext );
172
172
assertEquals ("CC0000" , res .getValue ());
173
+ assertNull (res .getErrorCode ());
173
174
assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
174
175
assertEquals ("True" , res .getVariant ());
175
176
}
@@ -193,6 +194,7 @@ void should_resolve_a_valid_integer_flag_with_TARGETING_MATCH_reason() throws In
193
194
GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
194
195
ProviderEvaluation <Integer > res = g .getIntegerEvaluation ("integer_key" , 1200 , this .evaluationContext );
195
196
assertEquals (100 , res .getValue ());
197
+ assertNull (res .getErrorCode ());
196
198
assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
197
199
assertEquals ("True" , res .getVariant ());
198
200
}
@@ -216,6 +218,7 @@ void should_resolve_a_valid_double_flag_with_TARGETING_MATCH_reason() throws Inv
216
218
GoFeatureFlagProvider g = new GoFeatureFlagProvider (GoFeatureFlagProviderOptions .builder ().endpoint (this .baseUrl .toString ()).timeout (1000 ).build ());
217
219
ProviderEvaluation <Double > res = g .getDoubleEvaluation ("double_key" , 1200.25 , this .evaluationContext );
218
220
assertEquals (100.25 , res .getValue ());
221
+ assertNull (res .getErrorCode ());
219
222
assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
220
223
assertEquals ("True" , res .getVariant ());
221
224
}
@@ -234,6 +237,7 @@ void should_resolve_a_valid_value_flag_with_TARGETING_MATCH_reason() throws Inva
234
237
ProviderEvaluation <Value > res = g .getObjectEvaluation ("object_key" , null , this .evaluationContext );
235
238
Value want = new Value (new MutableStructure ().add ("test" , "test1" ).add ("test2" , false ).add ("test3" , 123.3 ).add ("test4" , 1 ));
236
239
assertEquals (want , res .getValue ());
240
+ assertNull (res .getErrorCode ());
237
241
assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
238
242
assertEquals ("True" , res .getVariant ());
239
243
}
@@ -244,6 +248,7 @@ void should_wrap_into_value_if_wrong_type() throws InvalidOptions {
244
248
ProviderEvaluation <Value > res = g .getObjectEvaluation ("string_key" , null , this .evaluationContext );
245
249
Value want = new Value ("CC0000" );
246
250
assertEquals (want , res .getValue ());
251
+ assertNull (res .getErrorCode ());
247
252
assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
248
253
assertEquals ("True" , res .getVariant ());
249
254
}
@@ -274,6 +279,7 @@ void should_throw_an_error_if_no_targeting_key() throws InvalidOptions {
274
279
new Value ("false" ),
275
280
new Value ("test3" ))));
276
281
assertEquals (want , res .getValue ());
282
+ assertNull (res .getErrorCode ());
277
283
assertEquals (Reason .TARGETING_MATCH .toString (), res .getReason ());
278
284
assertEquals ("True" , res .getVariant ());
279
285
}
0 commit comments