Skip to content

Commit 22ba608

Browse files
committed
Added tests for server.* attribute extraction
1 parent 149ffbd commit 22ba608

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package io.opentelemetry.exporter.internal;
2+
3+
import io.opentelemetry.sdk.internal.SemConvAttributes;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
7+
8+
public class ServerAttributesUtilTest {
9+
10+
@Test
11+
public void invalidUrl() {
12+
assertThat(ServerAttributesUtil.extractServerAttributes("^"))
13+
.isEmpty();
14+
}
15+
16+
@Test
17+
public void emptyUrl() {
18+
assertThat(ServerAttributesUtil.extractServerAttributes(""))
19+
.isEmpty();
20+
}
21+
22+
@Test
23+
public void testHttps() {
24+
assertThat(ServerAttributesUtil.extractServerAttributes("https://example.com/foo/bar?a=b"))
25+
.hasSize(2)
26+
.containsEntry(SemConvAttributes.SERVER_ADDRESS, "example.com")
27+
.containsEntry(SemConvAttributes.SERVER_PORT, 443);
28+
29+
assertThat(ServerAttributesUtil.extractServerAttributes("https://example.com:1234/foo/bar?a=b"))
30+
.hasSize(2)
31+
.containsEntry(SemConvAttributes.SERVER_ADDRESS, "example.com")
32+
.containsEntry(SemConvAttributes.SERVER_PORT, 1234);
33+
}
34+
35+
@Test
36+
public void testHttp() {
37+
assertThat(ServerAttributesUtil.extractServerAttributes("http://example.com/foo/bar?a=b"))
38+
.hasSize(2)
39+
.containsEntry(SemConvAttributes.SERVER_ADDRESS, "example.com")
40+
.containsEntry(SemConvAttributes.SERVER_PORT, 80);
41+
42+
assertThat(ServerAttributesUtil.extractServerAttributes("http://example.com:1234/foo/bar?a=b"))
43+
.hasSize(2)
44+
.containsEntry(SemConvAttributes.SERVER_ADDRESS, "example.com")
45+
.containsEntry(SemConvAttributes.SERVER_PORT, 1234);
46+
}
47+
48+
@Test
49+
public void unknownScheme() {
50+
assertThat(ServerAttributesUtil.extractServerAttributes("custom://foo"))
51+
.hasSize(1)
52+
.containsEntry(SemConvAttributes.SERVER_ADDRESS, "foo");
53+
54+
assertThat(ServerAttributesUtil.extractServerAttributes("custom://foo:1234"))
55+
.hasSize(2)
56+
.containsEntry(SemConvAttributes.SERVER_ADDRESS, "foo")
57+
.containsEntry(SemConvAttributes.SERVER_PORT, 1234);
58+
}
59+
}

0 commit comments

Comments
 (0)