Skip to content

Commit c967058

Browse files
authored
add unit test for jar command variant
1 parent dfd61ab commit c967058

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

instrumentation/resources/library/src/test/java/io/opentelemetry/instrumentation/resources/JarServiceNameDetectorTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ void createResource_processHandleJar() {
7373
.containsEntry(ServiceAttributes.SERVICE_NAME, "my-service");
7474
}
7575

76+
@Test
77+
void createResource_processHandleJar_jar_command_variant() {
78+
JarServiceNameDetector serviceNameProvider =
79+
getDetector(
80+
getArgs_jar_command_variant("my-service.jar"),
81+
prop -> null,
82+
JarServiceNameDetectorTest::failPath);
83+
84+
Resource resource = serviceNameProvider.createResource(config);
85+
86+
assertThat(resource.getAttributes())
87+
.hasSize(1)
88+
.containsEntry(ServiceAttributes.SERVICE_NAME, "my-service");
89+
}
90+
7691
@Test
7792
void createResource_processHandleJarWithoutExtension() {
7893
JarServiceNameDetector serviceNameProvider =
@@ -90,6 +105,11 @@ static String[] getArgs(String jarName) {
90105
return new String[] {"-Dtest=42", "-Xmx666m", "-jar", path, "abc", "def"};
91106
}
92107

108+
static String[] getArgs_jar_command_variant(String jarName) {
109+
String path = Paths.get("path", "to", "app", jarName).toString();
110+
return new String[] {"-Dtest=42", "-jar", "-Xmx666m", path, "abc", "def"};
111+
}
112+
93113
@ParameterizedTest
94114
@ArgumentsSource(SunCommandLineProvider.class)
95115
void createResource_sunCommandLine(String commandLine, Path jarPath) {

0 commit comments

Comments
 (0)