|
5 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
6 | 6 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
7 | 7 |
|
| 8 | +import com.fasterxml.jackson.databind.ObjectMapper; |
8 | 9 | import com.github.benmanes.caffeine.cache.Caffeine;
|
9 | 10 | import com.google.common.net.HttpHeaders;
|
10 | 11 | import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidEndpoint;
|
|
21 | 22 | import dev.openfeature.sdk.Value;
|
22 | 23 | import java.io.IOException;
|
23 | 24 | import java.net.URL;
|
| 25 | +import java.nio.charset.Charset; |
24 | 26 | import java.nio.charset.StandardCharsets;
|
25 | 27 | import java.nio.file.Files;
|
26 | 28 | import java.nio.file.Paths;
|
@@ -48,12 +50,14 @@ class GoFeatureFlagProviderTest {
|
48 | 50 | private Map exporterMetadata;
|
49 | 51 | private int flagChangeCallCounter = 0;
|
50 | 52 | private boolean flagChanged404 = false;
|
| 53 | + private List<RecordedRequest> requests = new ArrayList<>(); |
51 | 54 |
|
52 | 55 | // Dispatcher is the configuration of the mock server to test the provider.
|
53 | 56 | final Dispatcher dispatcher = new Dispatcher() {
|
54 | 57 | @NotNull @SneakyThrows
|
55 | 58 | @Override
|
56 | 59 | public MockResponse dispatch(RecordedRequest request) {
|
| 60 | + requests.add(request); |
57 | 61 | assert request.getPath() != null;
|
58 | 62 | if (request.getPath().contains("fail_500")) {
|
59 | 63 | return new MockResponse().setResponseCode(500);
|
@@ -987,6 +991,42 @@ void should_send_exporter_metadata() {
|
987 | 991 | "we should have the exporter metadata in the last event sent to the data collector");
|
988 | 992 | }
|
989 | 993 |
|
| 994 | + @SneakyThrows |
| 995 | + @Test |
| 996 | + void should_add_exporter_metadata_into_evaluation_call() { |
| 997 | + Map<String, Object> customExporterMetadata = new HashMap<>(); |
| 998 | + customExporterMetadata.put("version", "1.0.0"); |
| 999 | + customExporterMetadata.put("intTest", 1234567890); |
| 1000 | + customExporterMetadata.put("doubleTest", 12345.67890); |
| 1001 | + GoFeatureFlagProvider g = new GoFeatureFlagProvider(GoFeatureFlagProviderOptions.builder() |
| 1002 | + .endpoint(this.baseUrl.toString()) |
| 1003 | + .timeout(1000) |
| 1004 | + .enableCache(true) |
| 1005 | + .flushIntervalMs(150L) |
| 1006 | + .exporterMetadata(customExporterMetadata) |
| 1007 | + .build()); |
| 1008 | + String providerName = this.testName; |
| 1009 | + OpenFeatureAPI.getInstance().setProviderAndWait(providerName, g); |
| 1010 | + Client client = OpenFeatureAPI.getInstance().getClient(providerName); |
| 1011 | + client.getBooleanDetails("bool_targeting_match", false, this.evaluationContext); |
| 1012 | + ObjectMapper objectMapper = new ObjectMapper(); |
| 1013 | + String want = objectMapper |
| 1014 | + .readValue( |
| 1015 | + "{ \"user\" : { \"key\" : \"d45e303a-38c2-11ed-a261-0242ac120002\", " |
| 1016 | + + "\"anonymous\" : false, \"custom\" : { \"firstname\" : \"john\", \"gofeatureflag\" : { " |
| 1017 | + + "\"exporterMetadata\" : { \"openfeature\" : true, \"provider\" : \"java\", \"doubleTest\" : 12345.6789, " |
| 1018 | + + "\"intTest\" : 1234567890, \"version\" : \"1.0.0\" } }, \"rate\" : 3.14, \"targetingKey\" : " |
| 1019 | + + "\"d45e303a-38c2-11ed-a261-0242ac120002\", \"company_info\" : { \"size\" : 120, \"name\" : \"my_company\" }, " |
| 1020 | + + "\"email\" : \"[email protected]\", \"age\" : 30, \"lastname\" : \"doe\", \"professional\" : true, " |
| 1021 | + + "\"labels\" : [ \"pro\", \"beta\" ] } }, \"defaultValue\" : false }", |
| 1022 | + Object.class) |
| 1023 | + .toString(); |
| 1024 | + String got = objectMapper |
| 1025 | + .readValue(this.requests.get(0).getBody().readString(Charset.defaultCharset()), Object.class) |
| 1026 | + .toString(); |
| 1027 | + assertEquals(want, got, "we should have the exporter metadata in the last event sent to the data collector"); |
| 1028 | + } |
| 1029 | + |
990 | 1030 | private String readMockResponse(String filename) throws Exception {
|
991 | 1031 | URL url = getClass().getClassLoader().getResource("mock_responses/" + filename);
|
992 | 1032 | assert url != null;
|
|
0 commit comments