|
2 | 2 |
|
3 | 3 | import static datadog.trace.api.config.FeatureFlaggingConfig.FEATURE_FLAGS_CONFIGURATION_SOURCE; |
4 | 4 | import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIGURATION_ENABLED; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertNull; |
5 | 8 | import static org.junit.jupiter.api.Assertions.assertThrows; |
6 | 9 | import static org.mockito.ArgumentMatchers.any; |
7 | 10 | import static org.mockito.ArgumentMatchers.eq; |
@@ -64,4 +67,67 @@ void testThatRemoteConfigIsRequired() { |
64 | 67 | FeatureFlaggingSystem.stop(); |
65 | 68 | } |
66 | 69 | } |
| 70 | + |
| 71 | + @Test |
| 72 | + @WithConfig(key = FEATURE_FLAGS_CONFIGURATION_SOURCE, value = "agentless") |
| 73 | + @WithConfig(key = REMOTE_CONFIGURATION_ENABLED, value = "false") |
| 74 | + void agentlessConfigurationSourceUsesHttpServiceWithoutRemoteConfig() { |
| 75 | + assertInstanceOf( |
| 76 | + AgentlessConfigurationSource.class, |
| 77 | + FeatureFlaggingSystem.createConfigurationSourceService( |
| 78 | + sharedCommunicationObjects(), Config.get())); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + @WithConfig(key = FEATURE_FLAGS_CONFIGURATION_SOURCE, value = "remote_config") |
| 83 | + @WithConfig(key = REMOTE_CONFIGURATION_ENABLED, value = "true") |
| 84 | + void explicitRemoteConfigUsesRemoteConfigService() { |
| 85 | + SharedCommunicationObjects sharedCommunicationObjects = sharedCommunicationObjects(); |
| 86 | + when(sharedCommunicationObjects.configurationPoller(any(Config.class))) |
| 87 | + .thenReturn(mock(ConfigurationPoller.class)); |
| 88 | + |
| 89 | + assertInstanceOf( |
| 90 | + RemoteConfigServiceImpl.class, |
| 91 | + FeatureFlaggingSystem.createConfigurationSourceService( |
| 92 | + sharedCommunicationObjects, Config.get())); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + @WithConfig(key = FEATURE_FLAGS_CONFIGURATION_SOURCE, value = "invalid") |
| 97 | + void invalidConfigurationSourceFailsBeforeStartingNetworkSource() { |
| 98 | + assertThrows( |
| 99 | + IllegalArgumentException.class, |
| 100 | + () -> |
| 101 | + FeatureFlaggingSystem.createConfigurationSourceService( |
| 102 | + sharedCommunicationObjects(), Config.get())); |
| 103 | + } |
| 104 | + |
| 105 | + @Test |
| 106 | + @WithConfig(key = FEATURE_FLAGS_CONFIGURATION_SOURCE, value = "offline") |
| 107 | + void offlineConfigurationSourceDoesNotStartNetworkSource() { |
| 108 | + assertNull( |
| 109 | + FeatureFlaggingSystem.createConfigurationSourceService( |
| 110 | + sharedCommunicationObjects(), Config.get())); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + @WithConfig(key = FEATURE_FLAGS_CONFIGURATION_SOURCE, value = "offline") |
| 115 | + void startWithOfflineConfigurationSourceSkipsConfigService() { |
| 116 | + try { |
| 117 | + assertDoesNotThrow(() -> FeatureFlaggingSystem.start(sharedCommunicationObjects())); |
| 118 | + } finally { |
| 119 | + FeatureFlaggingSystem.stop(); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + private static SharedCommunicationObjects sharedCommunicationObjects() { |
| 124 | + DDAgentFeaturesDiscovery discovery = mock(DDAgentFeaturesDiscovery.class); |
| 125 | + when(discovery.supportsEvpProxy()).thenReturn(true); |
| 126 | + when(discovery.getEvpProxyEndpoint()).thenReturn("/evp_proxy/"); |
| 127 | + SharedCommunicationObjects sharedCommunicationObjects = mock(SharedCommunicationObjects.class); |
| 128 | + when(sharedCommunicationObjects.featuresDiscovery(any(Config.class))).thenReturn(discovery); |
| 129 | + sharedCommunicationObjects.agentUrl = HttpUrl.get("http://localhost"); |
| 130 | + sharedCommunicationObjects.agentHttpClient = new OkHttpClient.Builder().build(); |
| 131 | + return sharedCommunicationObjects; |
| 132 | + } |
67 | 133 | } |
0 commit comments