Skip to content

Commit

Permalink
move security manager tests to their own suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeluca committed Sep 15, 2024
1 parent 056146b commit 782c70e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 75 deletions.
18 changes: 18 additions & 0 deletions instrumentation/resources/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,21 @@ tasks {
)
}
}

testing {
suites {
// Security Manager tests involve setup that can poison the environment for other tests
val testSecurityManager by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":instrumentation:resources:library"))
implementation("io.opentelemetry:opentelemetry-sdk-common")
}
}
}
}

tasks {
check {
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.SchemaUrls;
import io.opentelemetry.semconv.incubating.HostIncubatingAttributes;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;

class HostResourceTest {
@Test
Expand All @@ -30,18 +25,4 @@ void shouldCreateRuntimeAttributes() {
assertThat(attributes.get(HostIncubatingAttributes.HOST_NAME)).isNotBlank();
assertThat(attributes.get(HostIncubatingAttributes.HOST_ARCH)).isNotBlank();
}

@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_16},
disabledReason = "Java 17 deprecates security manager for removal")
static class SecurityManagerEnabled {
@Test
void empty() {
Attributes attributes = HostResource.buildResource().getAttributes();
assertThat(attributes.asMap()).containsOnlyKeys(HostIncubatingAttributes.HOST_NAME);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.SchemaUrls;
import io.opentelemetry.semconv.incubating.OsIncubatingAttributes;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.SetSystemProperty;

class OsResourceTest {
Expand Down Expand Up @@ -138,17 +133,4 @@ void unknown() {
assertThat(resource.getAttribute(OsIncubatingAttributes.OS_TYPE)).isNull();
assertThat(resource.getAttribute(OsIncubatingAttributes.OS_DESCRIPTION)).isNotEmpty();
}

@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_16},
disabledReason = "Java 17 deprecates security manager for removal")
static class SecurityManagerEnabled {
@Test
void empty() {
assertThat(OsResource.buildResource()).isEqualTo(Resource.empty());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.SchemaUrls;
import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.SetSystemProperty;

class ProcessResourceTest {
Expand Down Expand Up @@ -52,18 +47,4 @@ void windows() {
// With Java 9+ and a compiled jar, ResourceAttributes.PROCESS_COMMAND_ARGS
// will be set instead of ResourceAttributes.PROCESS_COMMAND_LINE
}

@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_16},
disabledReason = "Java 17 deprecates security manager for removal")
static class SecurityManagerEnabled {
@Test
void empty() {
Attributes attributes = ProcessResource.buildResource().getAttributes();
assertThat(attributes.asMap()).containsOnlyKeys(ProcessIncubatingAttributes.PROCESS_PID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.SchemaUrls;
import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;

class ProcessRuntimeResourceTest {
@Test
Expand All @@ -32,17 +27,4 @@ void shouldCreateRuntimeAttributes() {
assertThat(attributes.get(ProcessIncubatingAttributes.PROCESS_RUNTIME_DESCRIPTION))
.isNotBlank();
}

@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_16},
disabledReason = "Java 17 deprecates security manager for removal")
static class SecurityManagerEnabled {
@Test
void empty() {
assertThat(ProcessRuntimeResource.buildResource()).isEqualTo(Resource.empty());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void endToEnd() {
.collect(Collectors.toSet());
// ContainerResourceComponentProvider - no container attributes reliably provided
// HostIdResourceComponentProvider - host.id attribute not reliably provided
// HostResourceComponentProvider - host.arch attribute not reliably provided
// HostResourceComponentProvider
assertThat(attributeKeys).contains("host.arch");
assertThat(attributeKeys).contains("host.name");
// OsResourceComponentProvider
assertThat(attributeKeys).contains("os.description");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.resources;

import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.resources.Resource;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SecurityManagerExtension.class)
@EnabledOnJre(
value = {JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_16},
disabledReason = "Java 17 deprecates security manager for removal")
class SecurityManagerResourceTest {

@Test
void hostResourceTestEmpty() {
Attributes attributes = HostResource.buildResource().getAttributes();
assertThat(attributes.asMap()).containsOnlyKeys(AttributeKey.stringKey("host.name"));
}

@Test
void osResourceEmpty() {
assertThat(OsResource.buildResource()).isEqualTo(Resource.empty());
}

@Test
void processResourceEmpty() {
Attributes attributes = ProcessResource.buildResource().getAttributes();
assertThat(attributes.asMap()).containsOnlyKeys(AttributeKey.longKey("process.pid"));
}

@Test
void processRuntimeResourceEmpty() {
assertThat(ProcessRuntimeResource.buildResource()).isEqualTo(Resource.empty());
}
}

0 comments on commit 782c70e

Please sign in to comment.