Skip to content

Commit 8b0e1f8

Browse files
authored
Convert gcp-auth-extension to use test suites (#2342)
1 parent e8e2b89 commit 8b0e1f8

File tree

1 file changed

+51
-40
lines changed

1 file changed

+51
-40
lines changed

gcp-auth-extension/build.gradle.kts

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,59 @@ dependencies {
5353
agent("io.opentelemetry.javaagent:opentelemetry-javaagent")
5454
}
5555

56-
tasks {
57-
test {
58-
useJUnitPlatform()
59-
// Unset relevant environment variables to provide a clean state for the tests
60-
environment("GOOGLE_CLOUD_PROJECT", "")
61-
environment("GOOGLE_CLOUD_QUOTA_PROJECT", "")
62-
// exclude integration test
63-
exclude("io/opentelemetry/contrib/gcp/auth/GcpAuthExtensionEndToEndTest.class")
56+
testing {
57+
suites {
58+
val test by getting(JvmTestSuite::class) {
59+
targets.all {
60+
testTask.configure {
61+
// Unset relevant environment variables to provide a clean state for the tests
62+
environment("GOOGLE_CLOUD_PROJECT", "")
63+
environment("GOOGLE_CLOUD_QUOTA_PROJECT", "")
64+
// exclude integration test
65+
exclude("io/opentelemetry/contrib/gcp/auth/GcpAuthExtensionEndToEndTest.class")
66+
}
67+
}
68+
}
69+
70+
val integrationTestUserCreds by registering(JvmTestSuite::class) {
71+
dependencies {
72+
implementation(project())
73+
}
74+
75+
targets.all {
76+
testTask.configure {
77+
dependsOn(tasks.shadowJar)
78+
dependsOn(tasks.named("copyAgent"))
79+
80+
// include only the integration test file
81+
include("io/opentelemetry/contrib/gcp/auth/GcpAuthExtensionEndToEndTest.class")
82+
83+
val fakeCredsFilePath = project.file("src/test/resources/fake_user_creds.json").absolutePath
84+
85+
environment("GOOGLE_CLOUD_QUOTA_PROJECT", "quota-project-id")
86+
environment("GOOGLE_APPLICATION_CREDENTIALS", fakeCredsFilePath)
87+
jvmArgs(
88+
"-javaagent:$javaAgentJarPath",
89+
"-Dotel.javaagent.extensions=$authExtensionJarPath",
90+
"-Dgoogle.cloud.project=my-gcp-project",
91+
"-Dotel.java.global-autoconfigure.enabled=true",
92+
"-Dotel.exporter.otlp.endpoint=http://localhost:4318",
93+
"-Dotel.resource.providers.gcp.enabled=true",
94+
"-Dotel.traces.exporter=otlp",
95+
"-Dotel.bsp.schedule.delay=2000",
96+
"-Dotel.metrics.exporter=none",
97+
"-Dotel.logs.exporter=none",
98+
"-Dotel.exporter.otlp.protocol=http/protobuf",
99+
"-Dotel.javaagent.debug=false",
100+
"-Dmockserver.logLevel=trace"
101+
)
102+
}
103+
}
104+
}
64105
}
106+
}
65107

108+
tasks {
66109
shadowJar {
67110
/**
68111
* Shaded version of this extension is required when using it as a OpenTelemetry Java Agent
@@ -101,35 +144,3 @@ tasks.register<Copy>("copyAgent") {
101144
rename("opentelemetry-javaagent(.*).jar", "otel-agent.jar")
102145
})
103146
}
104-
105-
tasks.register<Test>("IntegrationTestUserCreds") {
106-
testClassesDirs = sourceSets.test.get().output.classesDirs
107-
classpath = sourceSets.test.get().runtimeClasspath
108-
109-
dependsOn(tasks.shadowJar)
110-
dependsOn(tasks.named("copyAgent"))
111-
112-
useJUnitPlatform()
113-
// include only the integration test file
114-
include("io/opentelemetry/contrib/gcp/auth/GcpAuthExtensionEndToEndTest.class")
115-
116-
val fakeCredsFilePath = project.file("src/test/resources/fake_user_creds.json").absolutePath
117-
118-
environment("GOOGLE_CLOUD_QUOTA_PROJECT", "quota-project-id")
119-
environment("GOOGLE_APPLICATION_CREDENTIALS", fakeCredsFilePath)
120-
jvmArgs = listOf(
121-
"-javaagent:$javaAgentJarPath",
122-
"-Dotel.javaagent.extensions=$authExtensionJarPath",
123-
"-Dgoogle.cloud.project=my-gcp-project",
124-
"-Dotel.java.global-autoconfigure.enabled=true",
125-
"-Dotel.exporter.otlp.endpoint=http://localhost:4318",
126-
"-Dotel.resource.providers.gcp.enabled=true",
127-
"-Dotel.traces.exporter=otlp",
128-
"-Dotel.bsp.schedule.delay=2000",
129-
"-Dotel.metrics.exporter=none",
130-
"-Dotel.logs.exporter=none",
131-
"-Dotel.exporter.otlp.protocol=http/protobuf",
132-
"-Dotel.javaagent.debug=false",
133-
"-Dmockserver.logLevel=trace"
134-
)
135-
}

0 commit comments

Comments
 (0)