Skip to content

Commit 0255e8e

Browse files
authored
Add NamingConventionTest (#3814)
* verify some behaviors of the NamingConvention class. * document that system property hyphens and underscores don't actually normalize the same * spotless
1 parent 38c8f89 commit 0255e8e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.config;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
public class NamingConventionTest {
13+
14+
@Test
15+
void normalizeEnvWithHyphen() {
16+
// Unlikely that the environment can contain a name like this, but let's doc the behavior
17+
String result = NamingConvention.ENV_VAR.normalize("FOO_BAR-BAZ");
18+
assertEquals("foo.bar-baz", result);
19+
}
20+
21+
@Test
22+
void systemPropertyWithHyphen() {
23+
// Normalizes to the same thing
24+
String result1 =
25+
NamingConvention.ENV_VAR.normalize(
26+
"OTEL_INSTRUMENTATION_COMMON_DB_STATEMENT_SANITIZER_ENABLED");
27+
String result2 =
28+
NamingConvention.DOT.normalize(
29+
"otel.instrumentation.common.db-statement-sanitizer.enabled");
30+
assertEquals("otel.instrumentation.common.db.statement.sanitizer.enabled", result1);
31+
assertEquals("otel.instrumentation.common.db.statement.sanitizer.enabled", result2);
32+
}
33+
34+
@Test
35+
void hyphensAndUnderscoresDoNotNormalizeTheSame() {
36+
String result1 = NamingConvention.DOT.normalize("otel.something_else_entirely.foobar");
37+
assertEquals("otel.something_else_entirely.foobar", result1);
38+
39+
String result2 = NamingConvention.DOT.normalize("otel.something-else-entirely.foobar");
40+
assertEquals("otel.something.else.entirely.foobar", result2);
41+
}
42+
}

0 commit comments

Comments
 (0)