Skip to content

Commit bd25fd5

Browse files
committed
More tests in TestBuildInfoPluginFuncTest
1 parent 1bfd312 commit bd25fd5

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/TestBuildInfoPluginFuncTest.groovy

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import com.fasterxml.jackson.databind.ObjectMapper
55
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
66
import org.gradle.testkit.runner.TaskOutcome
77

8+
import java.nio.file.Path
9+
810
class TestBuildInfoPluginFuncTest extends AbstractGradleFuncTest {
9-
def "works"() {
11+
def "basic functionality"() {
1012
given:
1113
file("src/main/java/com/example/Example.java") << """
1214
package com.example;
@@ -60,4 +62,63 @@ class TestBuildInfoPluginFuncTest extends AbstractGradleFuncTest {
6062
)
6163
new ObjectMapper().readValue(output, Map.class) == expectedOutput
6264
}
65+
66+
def "dependencies"() {
67+
buildFile << """
68+
import org.elasticsearch.gradle.plugin.GenerateTestBuildInfoTask;
69+
70+
plugins {
71+
id 'java'
72+
id 'elasticsearch.test-build-info'
73+
}
74+
75+
repositories {
76+
mavenCentral()
77+
}
78+
79+
dependencies {
80+
// We pin to specific versions here because they are known to have the properties we want to test.
81+
// We're not actually running this code.
82+
implementation "org.ow2.asm:asm:9.7.1" // has module-info.class
83+
implementation "junit:junit:4.13" // has Automatic-Module-Name, and brings in hamcrest which does not
84+
}
85+
86+
tasks.withType(GenerateTestBuildInfoTask.class) {
87+
componentName = 'example-component'
88+
outputFile = new File('build/generated-build-info/plugin-test-build-info.json')
89+
}
90+
"""
91+
92+
when:
93+
def result = gradleRunner('generateTestBuildInfo').build()
94+
def task = result.task(":generateTestBuildInfo")
95+
96+
97+
then:
98+
task.outcome == TaskOutcome.SUCCESS
99+
100+
def output = file("build/generated-build-info/plugin-test-build-info.json")
101+
output.exists() == true
102+
103+
def locationFromModuleInfo = Map.of(
104+
"module", "org.objectweb.asm",
105+
"representative_class", Path.of('org', 'objectweb', 'asm', 'AnnotationVisitor.class').toString()
106+
)
107+
def locationFromManifest = Map.of(
108+
"module", "junit",
109+
"representative_class", Path.of('junit', 'textui', 'TestRunner.class').toString()
110+
)
111+
def locationFromJarFileName = Map.of(
112+
"module", "hamcrest.core",
113+
"representative_class", Path.of('org', 'hamcrest', 'BaseDescription.class').toString()
114+
)
115+
def expectedOutput = Map.of(
116+
"component", "example-component",
117+
"locations", List.of(locationFromModuleInfo, locationFromManifest, locationFromJarFileName)
118+
)
119+
120+
def value = new ObjectMapper().readValue(output, Map.class)
121+
expectedOutput.forEach((k,v) -> value.get(k) == v)
122+
value == expectedOutput
123+
}
63124
}

0 commit comments

Comments
 (0)