-
Notifications
You must be signed in to change notification settings - Fork 791
/
ConfiguredResourceAttributesHolderTest.java
55 lines (44 loc) · 1.94 KB
/
ConfiguredResourceAttributesHolderTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.bootstrap;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ClearSystemProperty;
import org.junitpioneer.jupiter.SetSystemProperty;
class ConfiguredResourceAttributesHolderTest {
@Test
@SetSystemProperty(
key = "otel.instrumentation.mdc.resource-attributes",
value = "service.name,runtime")
void testGetAttributeValue() {
Attributes attributes =
Attributes.builder().put("service.name", "test-service").put("runtime", "JVM").build();
ConfiguredResourceAttributesHolder.initialize(attributes);
assertThat(ConfiguredResourceAttributesHolder.getAttributeValue("service.name"))
.isEqualTo("test-service");
assertThat(ConfiguredResourceAttributesHolder.getAttributeValue("runtime")).isEqualTo("JVM");
}
@Test
@SetSystemProperty(key = "otel.instrumentation.mdc.resource-attributes", value = "items")
void testGetAttributeValueWhenKeyIsNotString() {
Attributes attributes =
Attributes.builder()
.put(AttributeKey.stringArrayKey("items"), Collections.singletonList("test-item"))
.build();
ConfiguredResourceAttributesHolder.initialize(attributes);
assertThat(ConfiguredResourceAttributesHolder.getAttributeValue("items")).isNull();
}
@Test
@ClearSystemProperty(key = "otel.instrumentation.mdc.resource-attributes")
void testGetAttributeValueWhenConfigIsNotSet() {
Attributes attributes =
Attributes.builder().put(AttributeKey.stringArrayKey("don't care"), "won't care").build();
ConfiguredResourceAttributesHolder.initialize(attributes);
assertThat(ConfiguredResourceAttributesHolder.getAttributeValue("dc-wc")).isNull();
}
}