Skip to content

Commit 753c135

Browse files
authored
Fix broken Gradle Spock's integration (skips Groovy tests) (#19742)
* Fix broken Gradle Spock's integration (skips Groovy tests) Signed-off-by: Andriy Redko <drreta@gmail.com> * Address code review comments Signed-off-by: Andriy Redko <drreta@gmail.com> --------- Signed-off-by: Andriy Redko <drreta@gmail.com>
1 parent b6e6e3b commit 753c135

File tree

9 files changed

+29
-9
lines changed

9 files changed

+29
-9
lines changed

buildSrc/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ dependencies {
133133
integTestImplementation('org.spockframework:spock-core:2.4-M6-groovy-4.0') {
134134
exclude module: "groovy"
135135
}
136+
// Integration with JUnit 4 features for Spock 2+ (which internally uses JUnit Platform -
137+
// part of JUnit 5) - https://spockframework.org/spock/docs/2.4-M6/modules.html
138+
integTestImplementation('org.spockframework:spock-junit4:2.4-M6-groovy-4.0') {
139+
exclude module: "groovy"
140+
}
141+
integTestImplementation(platform("org.junit:junit-bom:${props.getProperty('junit5')}"))
142+
integTestRuntimeOnly("org.junit.platform:junit-platform-launcher")
143+
integTestRuntimeOnly("org.junit.vintage:junit-vintage-engine")
136144
}
137145

138146
configurations.all {
@@ -253,6 +261,7 @@ if (project != rootProject) {
253261
}
254262

255263
tasks.register("integTest", Test) {
264+
useJUnitPlatform()
256265
inputs.dir(file("src/testKit")).withPropertyName("testkit dir").withPathSensitivity(PathSensitivity.RELATIVE)
257266
systemProperty 'test.version_under_test', version
258267
onlyIf { org.opensearch.gradle.info.BuildParams.inFipsJvm == false }

buildSrc/src/integTest/groovy/org/opensearch/gradle/DistributionDownloadPluginFuncTest.groovy

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
5656
where:
5757
version | platform | distType
5858
VersionProperties.getOpenSearch() | OpenSearchDistribution.Platform.LINUX | "current"
59-
"8.1.0-SNAPSHOT" | OpenSearchDistribution.Platform.LINUX | "bwc"
60-
"7.0.0" | OpenSearchDistribution.Platform.WINDOWS | "released"
59+
"2.19.0-SNAPSHOT" | OpenSearchDistribution.Platform.LINUX | "bwc"
60+
"3.3.0" | OpenSearchDistribution.Platform.WINDOWS | "released"
6161
}
6262

6363

@@ -72,7 +72,8 @@ class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
7272
"""
7373

7474
when:
75-
def runner = gradleRunner('clean', 'setupDistro', '-i')
75+
def customGradleUserHome = testProjectDir.newFolder().absolutePath;
76+
def runner = gradleRunner('clean', 'setupDistro', '-i', '-g', customGradleUserHome)
7677
def result = withMockedDistributionDownload(version, platform, runner) {
7778
// initial run
7879
build()
@@ -82,7 +83,8 @@ class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
8283

8384
then:
8485
result.task(":setupDistro").outcome == TaskOutcome.SUCCESS
85-
assertOutputContains(result.output, "Skipping ${SymbolicLinkPreservingUntarTransform.class.simpleName}")
86+
result.output.count("Unpacking opensearch-${version}-linux-x64.tar.gz " +
87+
"using SymbolicLinkPreservingUntarTransform.") == 0
8688
}
8789

8890
def "transforms are reused across projects"() {
@@ -91,6 +93,7 @@ class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
9193
def platform = OpenSearchDistribution.Platform.LINUX
9294

9395
3.times {
96+
testProjectDir.newFolder("sub-$it")
9497
settingsFile << """
9598
include ':sub-$it'
9699
"""

buildSrc/src/integTest/groovy/org/opensearch/gradle/JdkDownloadPluginFuncTest.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
108108
def mockRepoUrl = urlPath(jdkVendor, jdkVersion, platform)
109109
def mockedContent = filebytes(jdkVendor, platform)
110110
3.times {
111+
testProjectDir.newFolder("sub-$it")
111112
settingsFile << """
112113
include ':sub-$it'
113114
"""
@@ -193,7 +194,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
193194
}
194195

195196
then:
196-
assertOutputContains(result.output, "Skipping $transformType")
197+
result.output.count("Unpacking ${platform}-12.0.2-x64.tar.gz using ${transformType}.") == 0
197198

198199
where:
199200
platform | transformType
@@ -246,6 +247,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
246247
p.repositories.all { repo ->
247248
if(repo.name == "jdk_repo_${jdkVendor}_${jdkVersion}") {
248249
repo.setUrl('${server.baseUrl()}')
250+
repo.setAllowInsecureProtocol(true)
249251
}
250252
}
251253
}"""

buildSrc/src/integTest/groovy/org/opensearch/gradle/internal/InternalDistributionArchiveSetupPluginFuncTest.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class InternalDistributionArchiveSetupPluginFuncTest extends AbstractGradleFuncT
9898
given:
9999
file('someFile.txt') << "some content"
100100

101+
testProjectDir.newFolder("consumer")
102+
testProjectDir.newFolder("producer-tar")
103+
101104
settingsFile << """
102105
include ':consumer'
103106
include ':producer-tar'

buildSrc/src/integTest/groovy/org/opensearch/gradle/internal/InternalDistributionDownloadPluginFuncTest.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
122122
internalBuild()
123123
bwcMinorProjectSetup()
124124
buildFile << """
125+
import org.opensearch.gradle.JavaPackageType
126+
125127
apply plugin: 'opensearch.internal-distribution-download'
126128
127129
opensearch_distributions {
@@ -130,7 +132,7 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
130132
type = "archive"
131133
platform = "linux"
132134
architecture = Architecture.current();
133-
bundledJdk = false
135+
bundledJdk = JavaPackageType.NONE
134136
}
135137
}
136138
tasks.register("createExtractedTestDistro") {

buildSrc/src/integTest/resources/org/opensearch/gradle/internal/fake_git/remote/distribution/archives/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ subprojects {
3232
apply plugin:'base'
3333

3434
tasks.register('tar', Tar) {
35-
from('.')
35+
from('build.gradle')
3636
destinationDirectory.set(file('build/distributions'))
3737
archiveBaseName.set("opensearch")
3838
archiveVersion.set("8.0.1-SNAPSHOT")

buildSrc/src/testKit/testingConventions/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ allprojects {
2121
mavenCentral()
2222
}
2323
dependencies {
24-
testImplementation "junit:junit:4.13.2"
24+
testImplementation "junit:junit:${versions.junit}"
2525
}
2626

2727
ext.licenseFile = file("$buildDir/dummy/license")

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ password4j = "1.8.3"
7474
# test dependencies
7575
randomizedrunner = "2.7.1"
7676
junit = "4.13.2"
77+
junit5 = "6.0.0"
7778
hamcrest = "2.1"
7879
mockito = "5.16.1"
7980
objenesis = "3.3"

plugins/identity-shiro/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies {
3333
testImplementation project(path: ':modules:transport-netty4') // for http
3434
testImplementation "org.mockito:mockito-core:${versions.mockito}"
3535
testImplementation project(path: ':client:rest-high-level')
36-
testImplementation 'junit:junit:4.13.2'
36+
testImplementation "junit:junit:${versions.junit}"
3737
}
3838

3939
/*

0 commit comments

Comments
 (0)