|
20 | 20 |
|
21 | 21 | import static org.assertj.core.api.Assertions.assertThat; |
22 | 22 |
|
| 23 | +import io.opentelemetry.instrumentation.resources.ResourceProviderPropertiesCustomizer; |
23 | 24 | import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; |
| 25 | +import java.lang.reflect.Field; |
| 26 | +import java.util.Arrays; |
24 | 27 | import java.util.Collections; |
25 | 28 | import java.util.HashMap; |
| 29 | +import java.util.List; |
26 | 30 | import java.util.Map; |
27 | 31 | import org.junit.jupiter.api.Test; |
28 | 32 |
|
29 | 33 | class ResourcesAutoConfigurationTest { |
30 | 34 |
|
31 | | - public static final String GCP_ENABLED = "otel.resource.providers.gcp.enabled"; |
32 | | - public static final String AWS_ENABLED = "otel.resource.providers.aws.enabled"; |
33 | | - public static final String AZURE_ENABLED = "otel.resource.providers.azure.enabled"; |
| 35 | + private static final List<String> LIST = Arrays.asList( |
| 36 | + config("gcp"), |
| 37 | + config("aws"), |
| 38 | + config("azure")); |
| 39 | + |
| 40 | + private static String config(String provider) { |
| 41 | + return String.format("otel.resource.providers.%s.enabled", provider); |
| 42 | + } |
34 | 43 |
|
35 | 44 | @Test |
36 | 45 | void elastic_defaults() { |
37 | 46 | // default everything should be enabled |
38 | 47 |
|
39 | 48 | Map<String, String> explicitConfig = Collections.emptyMap(); |
40 | 49 | Map<String, String> expectedResult = new HashMap<>(); |
41 | | - expectedResult.put(GCP_ENABLED, "true"); |
42 | | - expectedResult.put(AWS_ENABLED, "true"); |
43 | | - expectedResult.put(AZURE_ENABLED, "true"); |
| 50 | + |
| 51 | + LIST.forEach(v -> expectedResult.put(v, "true")); |
44 | 52 |
|
45 | 53 | testConfig(explicitConfig, expectedResult); |
46 | 54 | } |
47 | 55 |
|
48 | 56 | @Test |
49 | 57 | void explicitly_enabled() { |
50 | 58 | Map<String, String> explicitConfig = new HashMap<>(); |
51 | | - explicitConfig.put(GCP_ENABLED, "true"); |
| 59 | + explicitConfig.put(LIST.get(0), "true"); |
52 | 60 |
|
53 | 61 | Map<String, String> expectedResult = new HashMap<>(); |
54 | | - expectedResult.put(GCP_ENABLED, "true"); |
55 | | - expectedResult.put(AWS_ENABLED, "true"); |
56 | | - expectedResult.put(AZURE_ENABLED, "true"); |
| 62 | + LIST.forEach(v -> expectedResult.put(v, "true")); |
57 | 63 |
|
58 | 64 | testConfig(explicitConfig, expectedResult); |
59 | 65 | } |
60 | 66 |
|
61 | 67 | @Test |
62 | 68 | void explicitly_disabled() { |
63 | 69 | Map<String, String> explicitConfig = new HashMap<>(); |
64 | | - explicitConfig.put(GCP_ENABLED, "false"); |
| 70 | + explicitConfig.put(LIST.get(0), "false"); |
65 | 71 |
|
66 | 72 | Map<String, String> expectedResult = new HashMap<>(); |
67 | | - expectedResult.put(GCP_ENABLED, "false"); |
68 | | - expectedResult.put(AWS_ENABLED, "true"); |
69 | | - expectedResult.put(AZURE_ENABLED, "true"); |
| 73 | + expectedResult.put(LIST.get(0), "false"); |
| 74 | + for (int i = 1; i < LIST.size(); i++) { |
| 75 | + expectedResult.put(LIST.get(i), "true"); |
| 76 | + } |
70 | 77 |
|
71 | 78 | testConfig(explicitConfig, expectedResult); |
72 | 79 | } |
|
0 commit comments