|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package com.microsoft.applicationinsights.agent.internal.init; |
| 5 | + |
| 6 | +import static org.assertj.core.api.Assertions.assertThat; |
| 7 | + |
| 8 | +import java.util.stream.Stream; |
| 9 | + |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | +import org.junit.jupiter.params.ParameterizedTest; |
| 12 | +import org.junit.jupiter.params.provider.Arguments; |
| 13 | +import org.junit.jupiter.params.provider.MethodSource; |
| 14 | + |
| 15 | +class AiConfigCustomizerTest { |
| 16 | + |
| 17 | + @Test |
| 18 | + void isAksAttach() { |
| 19 | + assertThat(AiConfigCustomizer.isAksAttach("dummy-aks-namespace")).isTrue(); |
| 20 | + |
| 21 | + assertThat(AiConfigCustomizer.isAksAttach(null)).isFalse(); |
| 22 | + assertThat(AiConfigCustomizer.isAksAttach("")).isFalse(); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + void updateMetricsExporter_ExporterUnset() { |
| 27 | + |
| 28 | + assertThat(AiConfigCustomizer.updateMetricsExporter(null, null)) |
| 29 | + .isEqualTo("azure_monitor,otlp"); |
| 30 | + |
| 31 | + assertThat(AiConfigCustomizer.updateMetricsExporter("", null)) |
| 32 | + .isEqualTo("azure_monitor,otlp"); |
| 33 | + |
| 34 | + assertThat(AiConfigCustomizer.updateMetricsExporter(null, "true")) |
| 35 | + .isEqualTo("azure_monitor,otlp"); |
| 36 | + |
| 37 | + assertThat(AiConfigCustomizer.updateMetricsExporter(null, "True")) |
| 38 | + .isEqualTo("azure_monitor,otlp"); |
| 39 | + } |
| 40 | + |
| 41 | + static Stream<Arguments> stringPairs() { |
| 42 | + return Stream.of( |
| 43 | + Arguments.of("none", "none"), |
| 44 | + Arguments.of("azure_monitor", "azure_monitor,otlp"), |
| 45 | + Arguments.of("azure_monitor,otlp", "azure_monitor,otlp"), |
| 46 | + Arguments.of("otlp", "otlp")); |
| 47 | + } |
| 48 | + |
| 49 | + @ParameterizedTest |
| 50 | + @MethodSource("stringPairs") |
| 51 | + void updateMetricsExporter_ExporterSet_AMLE_Unset(String metricsExporter, String expectAzureMonitor) { |
| 52 | + assertThat(AiConfigCustomizer.updateMetricsExporter(metricsExporter, null)) |
| 53 | + .isEqualTo(expectAzureMonitor); |
| 54 | + assertThat(AiConfigCustomizer.updateMetricsExporter(metricsExporter, "")) |
| 55 | + .isEqualTo(expectAzureMonitor); |
| 56 | + } |
| 57 | + |
| 58 | + static Stream<Arguments> stringPairs2() { |
| 59 | + return Stream.of( |
| 60 | + Arguments.of("none", "azure_monitor,otlp"), |
| 61 | + Arguments.of("azure_monitor", "azure_monitor,otlp"), |
| 62 | + Arguments.of("azure_monitor,otlp", "azure_monitor,otlp"), |
| 63 | + Arguments.of("otlp", "otlp,azure_monitor")); |
| 64 | + } |
| 65 | + |
| 66 | + @ParameterizedTest |
| 67 | + @MethodSource("stringPairs2") |
| 68 | + void updateMetricsExporter_ExporterSet_AMLE_True(String metricsExporter, String expectAzureMonitor) { |
| 69 | + assertThat(AiConfigCustomizer.updateMetricsExporter(metricsExporter, "true")) |
| 70 | + .isEqualTo(expectAzureMonitor); |
| 71 | + assertThat(AiConfigCustomizer.updateMetricsExporter(metricsExporter, "True")) |
| 72 | + .isEqualTo(expectAzureMonitor); |
| 73 | + } |
| 74 | + |
| 75 | + static Stream<Arguments> stringPairs3() { |
| 76 | + return Stream.of( |
| 77 | + Arguments.of("none", "none"), |
| 78 | + Arguments.of("azure_monitor", "azure_monitor"), |
| 79 | + Arguments.of("azure_monitor,otlp", "azure_monitor"), |
| 80 | + Arguments.of("otlp", "otlp")); |
| 81 | + } |
| 82 | + |
| 83 | + @ParameterizedTest |
| 84 | + @MethodSource("stringPairs3") |
| 85 | + void updateMetricsExporter_ExporterSet_AMLE_False(String metricsExporter, String expectAzureMonitor) { |
| 86 | + assertThat(AiConfigCustomizer.updateMetricsExporter(metricsExporter, "false")) |
| 87 | + .isEqualTo(expectAzureMonitor); |
| 88 | + assertThat(AiConfigCustomizer.updateMetricsExporter(metricsExporter, "False")) |
| 89 | + .isEqualTo(expectAzureMonitor); |
| 90 | + } |
| 91 | +} |
0 commit comments