Skip to content

Commit 8d56d81

Browse files
Split CI Visibility test fixtures into a separate project
1 parent 54b1788 commit 8d56d81

File tree

22 files changed

+76
-29
lines changed

22 files changed

+76
-29
lines changed

dd-java-agent/agent-ci-visibility/build.gradle

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ buildscript {
2424

2525
plugins {
2626
id 'com.gradleup.shadow'
27-
id 'java-test-fixtures'
2827
}
2928

3029
apply from: "$rootDir/gradle/java.gradle"
@@ -39,28 +38,23 @@ dependencies {
3938
api libs.slf4j
4039

4140
implementation libs.bundles.asm
42-
implementation group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.12'
43-
implementation group: 'org.jacoco', name: 'org.jacoco.report', version: '0.8.12'
41+
implementation group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.13'
42+
implementation group: 'org.jacoco', name: 'org.jacoco.report', version: '0.8.13'
4443

4544
implementation project(':communication')
4645
implementation project(':components:json')
4746
implementation project(':internal-api')
4847
implementation project(':internal-api:internal-api-9')
4948

5049
testImplementation project(":utils:test-utils")
50+
testImplementation project(':dd-java-agent:testing')
5151
testImplementation("com.google.jimfs:jimfs:1.1") // an in-memory file system for testing code that works with files
5252

5353
testImplementation libs.scala
5454
testImplementation libs.kotlin
5555

56-
testFixturesApi project(':dd-java-agent:instrumentation-testing')
57-
testFixturesApi project(':utils:test-utils')
58-
59-
testFixturesApi group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.1'
60-
testFixturesApi group: 'org.freemarker', name: 'freemarker', version: '2.3.31'
61-
testFixturesApi group: 'com.jayway.jsonpath', name: 'json-path', version: '2.8.0'
62-
testFixturesApi group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.0'
63-
testFixturesApi group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.9.6'
56+
testImplementation group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.1'
57+
testImplementation group: 'org.freemarker', name: 'freemarker', version: '2.3.31'
6458

6559
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.9.2") // Required to update dependency lock files
6660
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apply from: "$rootDir/gradle/java.gradle"
2+
apply from: "$rootDir/gradle/version.gradle"
3+
4+
dependencies {
5+
api project(':dd-java-agent:agent-ci-visibility')
6+
api project(':dd-java-agent:instrumentation-testing')
7+
api project(':utils:test-utils')
8+
9+
api group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.1'
10+
api group: 'org.freemarker', name: 'freemarker', version: '2.3.31'
11+
api group: 'com.jayway.jsonpath', name: 'json-path', version: '2.8.0'
12+
api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.0'
13+
api group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.9.6'
14+
}
15+

dd-java-agent/agent-ci-visibility/src/testFixtures/groovy/datadog/trace/civisibility/CiVisibilityInstrumentationTest.groovy renamed to dd-java-agent/agent-ci-visibility/civisibility-testing/src/main/groovy/datadog/trace/civisibility/CiVisibilityInstrumentationTest.groovy

File renamed without changes.

dd-java-agent/agent-ci-visibility/src/testFixtures/groovy/datadog/trace/civisibility/CiVisibilitySmokeTest.groovy renamed to dd-java-agent/agent-ci-visibility/civisibility-testing/src/main/groovy/datadog/trace/civisibility/CiVisibilitySmokeTest.groovy

File renamed without changes.

dd-java-agent/agent-ci-visibility/src/testFixtures/groovy/datadog/trace/civisibility/CiVisibilityTestUtils.groovy renamed to dd-java-agent/agent-ci-visibility/civisibility-testing/src/main/groovy/datadog/trace/civisibility/CiVisibilityTestUtils.groovy

File renamed without changes.

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import datadog.trace.api.civisibility.config.TestFQN
1111
import datadog.trace.api.civisibility.config.TestIdentifier
1212
import datadog.trace.api.civisibility.config.TestMetadata
1313
import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector
14-
import datadog.trace.civisibility.CiVisibilityTestUtils
14+
import freemarker.core.Environment
15+
import freemarker.core.InvalidReferenceException
16+
import freemarker.template.Template
17+
import freemarker.template.TemplateException
18+
import freemarker.template.TemplateExceptionHandler
1519
import okhttp3.HttpUrl
1620
import okhttp3.OkHttpClient
1721
import org.apache.commons.io.IOUtils
@@ -233,7 +237,7 @@ class ConfigurationApiImplTest extends Specification {
233237
httpServer {
234238
handlers {
235239
prefix(path) {
236-
def expectedRequestBody = CiVisibilityTestUtils.getFreemarkerTemplate(requestTemplate, requestData)
240+
def expectedRequestBody = getFreemarkerTemplate(requestTemplate, requestData)
237241

238242
def response = response
239243
try {
@@ -242,7 +246,7 @@ class ConfigurationApiImplTest extends Specification {
242246
response.status(400).send(error.getMessage().bytes)
243247
}
244248

245-
def responseBody = CiVisibilityTestUtils.getFreemarkerTemplate(responseTemplate, responseData).bytes
249+
def responseBody = getFreemarkerTemplate(responseTemplate, responseData).bytes
246250
def header = request.getHeader("Accept-Encoding")
247251
def gzipSupported = header != null && header.contains("gzip")
248252
if (gzipSupported) {
@@ -315,4 +319,37 @@ class ConfigurationApiImplTest extends Specification {
315319
}
316320
return bitSet
317321
}
322+
323+
static final TemplateExceptionHandler SUPPRESS_EXCEPTION_HANDLER = new TemplateExceptionHandler() {
324+
@Override
325+
void handleTemplateException(TemplateException e, Environment environment, Writer writer) throws TemplateException {
326+
if (e instanceof InvalidReferenceException) {
327+
writer.write('"<VALUE_MISSING>"')
328+
} else {
329+
throw e
330+
}
331+
}
332+
}
333+
334+
static final freemarker.template.Configuration FREEMARKER = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_30) { {
335+
setClassLoaderForTemplateLoading(ConfigurationApiImplTest.classLoader, "")
336+
setDefaultEncoding("UTF-8")
337+
setTemplateExceptionHandler(SUPPRESS_EXCEPTION_HANDLER)
338+
setLogTemplateExceptions(false)
339+
setWrapUncheckedExceptions(true)
340+
setFallbackOnNullLoopVariable(false)
341+
setNumberFormat("0.######")
342+
}
343+
}
344+
345+
static String getFreemarkerTemplate(String templatePath, Map<String, Object> replacements, List<Map<?, ?>> replacementsSource = []) {
346+
try {
347+
Template coveragesTemplate = FREEMARKER.getTemplate(templatePath)
348+
StringWriter coveragesOut = new StringWriter()
349+
coveragesTemplate.process(replacements, coveragesOut)
350+
return coveragesOut.toString()
351+
} catch (Exception e) {
352+
throw new RuntimeException("Could not get Freemarker template " + templatePath + "; replacements map: " + replacements + "; replacements source: " + replacementsSource, e)
353+
}
354+
}
318355
}

dd-java-agent/instrumentation/junit-4.10/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tasks.named("compileLatestDepTestGroovy").configure {
1919
dependencies {
2020
compileOnly group: 'junit', name: 'junit', version: '4.10'
2121

22-
testImplementation testFixtures(project(':dd-java-agent:agent-ci-visibility'))
22+
testImplementation project(':dd-java-agent:agent-ci-visibility:civisibility-testing')
2323

2424
// version used below is not the minimum one that we support,
2525
// but the tests need to use it in order to be compliant with Spock 2.x

dd-java-agent/instrumentation/junit-4.10/cucumber-junit-4/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414
implementation project(':dd-java-agent:instrumentation:junit-4.10')
1515
compileOnly group: 'io.cucumber', name: 'cucumber-junit', version: '5.4.0'
1616

17-
testImplementation testFixtures(project(':dd-java-agent:agent-ci-visibility'))
17+
testImplementation project(':dd-java-agent:agent-ci-visibility:civisibility-testing')
1818

1919
// version used below is not the minimum one that we support,
2020
// but the tests need to use it in order to be compliant with Spock 2.x

dd-java-agent/instrumentation/junit-4.10/junit-4.13/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414
implementation project(':dd-java-agent:instrumentation:junit-4.10')
1515
compileOnly group: 'junit', name: 'junit', version: '4.13'
1616

17-
testImplementation testFixtures(project(':dd-java-agent:agent-ci-visibility'))
17+
testImplementation project(':dd-java-agent:agent-ci-visibility:civisibility-testing')
1818

1919
// version used below is not the minimum one that we support,
2020
// but the tests need to use it in order to be compliant with Spock 2.x

dd-java-agent/instrumentation/junit-4.10/munit-junit-4/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies {
1515
implementation project(':dd-java-agent:instrumentation:junit-4.10')
1616
compileOnly group: 'org.scalameta', name: 'munit_2.13', version: '0.7.28'
1717

18-
testImplementation testFixtures(project(':dd-java-agent:agent-ci-visibility'))
18+
testImplementation project(':dd-java-agent:agent-ci-visibility:civisibility-testing')
1919

2020
// version used below is not the minimum one that we support,
2121
// but the tests need to use it in order to be compliant with Spock 2.x

0 commit comments

Comments
 (0)