@@ -53,16 +53,64 @@ 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+
79+ // include only the integration test file
80+ include(" io/opentelemetry/contrib/gcp/auth/GcpAuthExtensionEndToEndTest.class" )
81+
82+ val fakeCredsFilePath = project.file(" src/test/resources/fake_user_creds.json" ).absolutePath
83+
84+ environment(" GOOGLE_CLOUD_QUOTA_PROJECT" , " quota-project-id" )
85+ environment(" GOOGLE_APPLICATION_CREDENTIALS" , fakeCredsFilePath)
86+
87+ val agentJar = configurations.named(" agent" ).map { it.singleFile.absolutePath }
88+ val extensionJarPath = tasks.shadowJar.flatMap { it.archiveFile }.map { it.asFile.absolutePath }
89+
90+ jvmArgumentProviders.add(CommandLineArgumentProvider {
91+ listOf (
92+ " -javaagent:${agentJar.get()} " ,
93+ " -Dotel.javaagent.extensions=${extensionJarPath.get()} " ,
94+ " -Dgoogle.cloud.project=my-gcp-project" ,
95+ " -Dotel.java.global-autoconfigure.enabled=true" ,
96+ " -Dotel.exporter.otlp.endpoint=http://localhost:4318" ,
97+ " -Dotel.resource.providers.gcp.enabled=true" ,
98+ " -Dotel.traces.exporter=otlp" ,
99+ " -Dotel.bsp.schedule.delay=2000" ,
100+ " -Dotel.metrics.exporter=none" ,
101+ " -Dotel.logs.exporter=none" ,
102+ " -Dotel.exporter.otlp.protocol=http/protobuf" ,
103+ " -Dotel.javaagent.debug=false" ,
104+ " -Dmockserver.logLevel=trace"
105+ )
106+ })
107+ }
108+ }
109+ }
64110 }
111+ }
65112
113+ tasks {
66114 shadowJar {
67115 /* *
68116 * Shaded version of this extension is required when using it as a OpenTelemetry Java Agent
@@ -90,46 +138,3 @@ tasks {
90138 dependsOn(shadowJar)
91139 }
92140}
93-
94- val builtLibsDir = layout.buildDirectory.dir(" libs" ).get().asFile.absolutePath
95- val javaAgentJarPath = " $builtLibsDir /otel-agent.jar"
96- val authExtensionJarPath = " ${tasks.shadowJar.get().archiveFile.get()} "
97-
98- tasks.register<Copy >(" copyAgent" ) {
99- into(layout.buildDirectory.dir(" libs" ))
100- from(configurations.named(" agent" ) {
101- rename(" opentelemetry-javaagent(.*).jar" , " otel-agent.jar" )
102- })
103- }
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