Skip to content

Commit c7e828c

Browse files
committed
Migrating additional ConfigTests using fake env vars
1 parent f69e043 commit c7e828c

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

internal-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,46 +1190,6 @@ class ConfigTest extends DDSpecification {
11901190
config.serviceName == 'unnamed-java-app'
11911191
}
11921192

1193-
def "get analytics sample rate"() {
1194-
setup:
1195-
environmentVariables.set("DD_FOO_ANALYTICS_SAMPLE_RATE", "0.5")
1196-
environmentVariables.set("DD_BAR_ANALYTICS_SAMPLE_RATE", "0.9")
1197-
// trace prefix form should take precedence over the old non-prefix form
1198-
environmentVariables.set("DD_ALIAS_ENV_ANALYTICS_SAMPLE_RATE", "0.8")
1199-
environmentVariables.set("DD_TRACE_ALIAS_ENV_ANALYTICS_SAMPLE_RATE", "0.4")
1200-
1201-
System.setProperty("dd.baz.analytics.sample-rate", "0.7")
1202-
System.setProperty("dd.buzz.analytics.sample-rate", "0.3")
1203-
// trace prefix form should take precedence over the old non-prefix form
1204-
System.setProperty("dd.alias-prop.analytics.sample-rate", "0.1")
1205-
System.setProperty("dd.trace.alias-prop.analytics.sample-rate", "0.2")
1206-
1207-
when:
1208-
String[] array = services.toArray(new String[0])
1209-
def value = Config.get().getInstrumentationAnalyticsSampleRate(array)
1210-
1211-
then:
1212-
value == expected
1213-
1214-
where:
1215-
// spotless:off
1216-
services | expected
1217-
["foo"] | 0.5f
1218-
["baz"] | 0.7f
1219-
["doesnotexist"] | 1.0f
1220-
["doesnotexist", "foo"] | 0.5f
1221-
["doesnotexist", "baz"] | 0.7f
1222-
["foo", "bar"] | 0.5f
1223-
["bar", "foo"] | 0.9f
1224-
["baz", "buzz"] | 0.7f
1225-
["buzz", "baz"] | 0.3f
1226-
["foo", "baz"] | 0.5f
1227-
["baz", "foo"] | 0.7f
1228-
["alias-env", "baz"] | 0.4f
1229-
["alias-prop", "foo"] | 0.2f
1230-
// spotless:on
1231-
}
1232-
12331193
def "verify api key loaded from file: #path"() {
12341194
setup:
12351195
environmentVariables.set(DD_API_KEY_ENV, "default-api-key")
@@ -2827,5 +2787,45 @@ class ConfigTest extends DDSpecification {
28272787
28282788
defaultValue = 10.0
28292789
}
2790+
2791+
def "get analytics sample rate"() {
2792+
setup:
2793+
environmentVariables.set("DD_FOO_ANALYTICS_SAMPLE_RATE", "0.5")
2794+
environmentVariables.set("DD_BAR_ANALYTICS_SAMPLE_RATE", "0.9")
2795+
// trace prefix form should take precedence over the old non-prefix form
2796+
environmentVariables.set("DD_ALIAS_ENV_ANALYTICS_SAMPLE_RATE", "0.8")
2797+
environmentVariables.set("DD_TRACE_ALIAS_ENV_ANALYTICS_SAMPLE_RATE", "0.4")
2798+
2799+
System.setProperty("dd.baz.analytics.sample-rate", "0.7")
2800+
System.setProperty("dd.buzz.analytics.sample-rate", "0.3")
2801+
// trace prefix form should take precedence over the old non-prefix form
2802+
System.setProperty("dd.alias-prop.analytics.sample-rate", "0.1")
2803+
System.setProperty("dd.trace.alias-prop.analytics.sample-rate", "0.2")
2804+
2805+
when:
2806+
String[] array = services.toArray(new String[0])
2807+
def value = Config.get().getInstrumentationAnalyticsSampleRate(array)
2808+
2809+
then:
2810+
value == expected
2811+
2812+
where:
2813+
// spotless:off
2814+
services | expected
2815+
["foo"] | 0.5f
2816+
["baz"] | 0.7f
2817+
["doesnotexist"] | 1.0f
2818+
["doesnotexist", "foo"] | 0.5f
2819+
["doesnotexist", "baz"] | 0.7f
2820+
["foo", "bar"] | 0.5f
2821+
["bar", "foo"] | 0.9f
2822+
["baz", "buzz"] | 0.7f
2823+
["buzz", "baz"] | 0.3f
2824+
["foo", "baz"] | 0.5f
2825+
["baz", "foo"] | 0.7f
2826+
["alias-env", "baz"] | 0.4f
2827+
["alias-prop", "foo"] | 0.2f
2828+
// spotless:on
2829+
}
28302830
}
28312831
}

0 commit comments

Comments
 (0)