Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd committed Oct 23, 2024
1 parent b7d8843 commit 10e0869
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class OidcDslTest: BaseGradleTest() {
""".trimIndent()
)
enableConfigurationCache(gradle)
enableProjectIsolation(gradle)
prepare(gradle.version, "printConfig", "-s")
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SigstoreSignTest: BaseGradleTest() {
""".trimIndent()
)
enableConfigurationCache(case.gradle)
enableProjectIsolation(case.gradle)
prepare(case.gradle.version, "signFile", "-s")
.build()
assertThat(projectDir.resolve("build/helloProps.txt.sigstore.json"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RemoveSigstoreAscTest : BaseGradleTest() {
// Gradle < 8.1 + configuration cache=on which is incompatible with signing plugin.
listOf(
TestedGradleAndSigstoreJava(
TestedGradle(GradleVersion.version("8.1"), ConfigurationCache.OFF),
TestedGradle(GradleVersion.version("8.1"), ConfigurationCache.OFF, ProjectIsolation.OFF),
SIGSTORE_JAVA_CURRENT_VERSION
)
)
Expand Down Expand Up @@ -147,6 +147,7 @@ class RemoveSigstoreAscTest : BaseGradleTest() {
""".trimIndent()
)
enableConfigurationCache(case.gradle)
enableProjectIsolation(case.gradle)
}

private fun SoftAssertions.assertSignatures(name: String, expectSigstoreAsc: Boolean = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class SigstorePublishSignTest : BaseGradleTest() {
""".trimIndent()
)
enableConfigurationCache(case.gradle)
enableProjectIsolation(case.gradle)
prepare(case.gradle.version, "publishAllPublicationsToTmpRepository", "-s")
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.Arguments.arguments
import java.io.File
import java.nio.file.Path
import kotlin.io.path.appendText

open class BaseGradleTest {
enum class ConfigurationCache {
ON, OFF
}
enum class ProjectIsolation {
ON, OFF
}

// to debug these tests, add .withDebug(true) before running a test in debug mode
protected val gradleRunner = GradleRunner.create().withPluginClasspath()
Expand Down Expand Up @@ -63,16 +67,16 @@ open class BaseGradleTest {
if (!isCI) {
// Execute a single combination only when running locally
return listOf(
TestedGradle(gradleVersions().first(), ConfigurationCache.ON)
TestedGradle(gradleVersions().first(), ConfigurationCache.ON, ProjectIsolation.ON)
)
}
return buildList {
addAll(
gradleVersions().map { TestedGradle(it, ConfigurationCache.ON) }
gradleVersions().map { TestedGradle(it, ConfigurationCache.ON, ProjectIsolation.ON) }
)
// Test the first and the last version without configuration cache
add(TestedGradle(gradleVersions().first(), ConfigurationCache.OFF))
add(TestedGradle(gradleVersions().last(), ConfigurationCache.OFF))
add(TestedGradle(gradleVersions().first(), ConfigurationCache.OFF, ProjectIsolation.OFF))
add(TestedGradle(gradleVersions().last(), ConfigurationCache.OFF, ProjectIsolation.OFF))
}
}

Expand Down Expand Up @@ -202,6 +206,23 @@ open class BaseGradleTest {
)
}

protected fun enableProjectIsolation(
gradle: TestedGradle,
) {
if (gradle.projectIsolation != ProjectIsolation.ON) {
return
}
require(gradle.configurationCache == ConfigurationCache.ON) {
"Project isolation requires Configuration Cache."
}
projectDir.resolve("gradle.properties").appendText(
"""
org.gradle.unsafe.isolated-projects=true
""".trimIndent()
)
}

protected fun assertSoftly(body: SoftAssertions.() -> Unit) =
SoftAssertions.assertSoftly(body)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ import org.gradle.util.GradleVersion
*/
data class TestedGradle(
val version: GradleVersion,
val configurationCache: BaseGradleTest.ConfigurationCache
val configurationCache: BaseGradleTest.ConfigurationCache,
val projectIsolation: BaseGradleTest.ProjectIsolation,
)

0 comments on commit 10e0869

Please sign in to comment.