Skip to content

Commit

Permalink
Run tests with more version combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
erichaagdev committed Nov 4, 2024
1 parent b237ffa commit ab12111
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 21 deletions.
81 changes: 62 additions & 19 deletions src/test/groovy/com/gradle/BaseInitScriptTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,26 @@ import java.util.stream.Collectors
import java.util.zip.GZIPOutputStream

abstract class BaseInitScriptTest extends Specification {

static final String DEVELOCITY_PLUGIN_VERSION = '3.18.1'
static final String CCUD_PLUGIN_VERSION = '2.0.2'

static final String DEVELOCITY_PLUGIN_ID = 'com.gradle.develocity'
static final String GRADLE_ENTERPRISE_PLUGIN_ID = 'com.gradle.enterprise'
static final String BUILD_SCAN_PLUGIN_ID = 'com.gradle.build-scan'

static final List<String> TESTED_DEVELOCITY_PLUGIN_VERSIONS = ['3.17', DEVELOCITY_PLUGIN_VERSION]
static final List<String> TESTED_GRADLE_ENTERPRISE_PLUGIN_VERSIONS = ['3.0', '3.16.2', DEVELOCITY_PLUGIN_VERSION] // Max is same as DV version, for now
static final List<String> TESTED_BUILD_SCAN_PLUGIN_VERSIONS = [
'1.0',
'1.16',
'2.0',
'2.4.2',
'3.0',
'3.16.2',
DEVELOCITY_PLUGIN_VERSION // Max is same as DV version, for now
]

static final TestGradleVersion GRADLE_3_X = new TestGradleVersion(GradleVersion.version('3.5.1'), 7, 9)
static final TestGradleVersion GRADLE_4_X = new TestGradleVersion(GradleVersion.version('4.10.3'), 7, 10)
static final TestGradleVersion GRADLE_5_X = new TestGradleVersion(GradleVersion.version('5.6.4'), 8, 12)
Expand All @@ -40,9 +57,31 @@ abstract class BaseInitScriptTest extends Specification {
static final List<TestGradleVersion> CONFIGURATION_CACHE_VERSIONS =
[GRADLE_7_X, GRADLE_8_0, GRADLE_8_X].intersect(ALL_VERSIONS)

static final List<TestGradleVersion> SETTINGS_PLUGIN_VERSIONS =
static final List<TestGradleVersion> DEVELOCITY_PLUGIN_GRADLE_VERSIONS =
[GRADLE_5_X, GRADLE_6_X, GRADLE_7_X, GRADLE_8_0, GRADLE_8_X].intersect(ALL_VERSIONS)

static final List<TestGradleVersion> GRADLE_ENTERPRISE_PLUGIN_GRADLE_VERSIONS =
[GRADLE_6_X, GRADLE_7_X, GRADLE_8_0, GRADLE_8_X].intersect(ALL_VERSIONS)

static final List<TestGradleVersion> BUILD_SCAN_PLUGIN_GRADLE_VERSIONS =
[GRADLE_3_X, GRADLE_4_X, GRADLE_5_X].intersect(ALL_VERSIONS)

// Creates an array of arrays formatted as [[testGradleVersion, pluginId, pluginVersion], ...]
static final List<List<Object>> ALL_DEVELOCITY_PLUGIN_VERSIONS =
[DEVELOCITY_PLUGIN_GRADLE_VERSIONS, [DEVELOCITY_PLUGIN_ID], TESTED_DEVELOCITY_PLUGIN_VERSIONS].combinations()

static final List<List<Object>> ALL_GRADLE_ENTERPRISE_PLUGIN_VERSIONS =
[GRADLE_ENTERPRISE_PLUGIN_GRADLE_VERSIONS, [GRADLE_ENTERPRISE_PLUGIN_ID], TESTED_GRADLE_ENTERPRISE_PLUGIN_VERSIONS].combinations()

static final List<List<Object>> ALL_BUILD_SCAN_PLUGIN_VERSIONS =
[BUILD_SCAN_PLUGIN_GRADLE_VERSIONS, [BUILD_SCAN_PLUGIN_ID], TESTED_BUILD_SCAN_PLUGIN_VERSIONS].combinations()

static final List<List<Object>> ALL_PLUGIN_VERSIONS = [
ALL_DEVELOCITY_PLUGIN_VERSIONS,
ALL_GRADLE_ENTERPRISE_PLUGIN_VERSIONS,
ALL_BUILD_SCAN_PLUGIN_VERSIONS
].collectMany {it }

static final String PUBLIC_BUILD_SCAN_ID = 'i2wepy2gr7ovw'
static final String DEFAULT_SCAN_UPLOAD_TOKEN = 'scan-upload-token'
static final String ROOT_PROJECT_NAME = 'test-init-script'
Expand Down Expand Up @@ -125,30 +164,37 @@ abstract class BaseInitScriptTest extends Specification {
buildFile << ''
}

def declarePluginApplication(GradleVersion gradleVersion, String pluginId, String pluginVersion, URI serverUrl = mockScansServer.address) {
settingsFile.text = maybeAddPluginsToSettings(gradleVersion, pluginId, pluginVersion, null, serverUrl) + settingsFile.text
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, pluginId, pluginVersion, null, serverUrl) + buildFile.text
if (pluginId != 'com.gradle.develocity' && GradleVersion.version(pluginVersion) >= GradleVersion.version('3.17')) allowDevelocityDeprecationWarning = true
}

def declareDevelocityPluginApplication(GradleVersion gradleVersion, URI serverUrl = mockScansServer.address) {
settingsFile.text = maybeAddPluginsToSettings(gradleVersion, false, null, serverUrl) + settingsFile.text
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, false, null, serverUrl) + buildFile.text
settingsFile.text = maybeAddPluginsToSettings(gradleVersion, 'com.gradle.develocity', DEVELOCITY_PLUGIN_VERSION, null, serverUrl) + settingsFile.text
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, 'com.gradle.develocity', DEVELOCITY_PLUGIN_VERSION, null, serverUrl) + buildFile.text
}

def declareLegacyGradleEnterprisePluginApplication(GradleVersion gradleVersion, URI serverUrl = mockScansServer.address) {
settingsFile.text = maybeAddPluginsToSettings(gradleVersion, true, null, serverUrl) + settingsFile.text
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, true, null, serverUrl) + buildFile.text
def pluginId = gradleVersion < GradleVersion.version('6.0') ? 'com.gradle.build-scan' : 'com.gradle.enterprise'
settingsFile.text = maybeAddPluginsToSettings(gradleVersion, pluginId, '3.16.2', null, serverUrl) + settingsFile.text
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, pluginId, '3.16.2', null, serverUrl) + buildFile.text
}

def declareDevelocityPluginAndCcudPluginApplication(GradleVersion gradleVersion, URI serverUrl = mockScansServer.address) {
settingsFile.text = maybeAddPluginsToSettings(gradleVersion, false, CCUD_PLUGIN_VERSION, serverUrl) + settingsFile.text
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, false, CCUD_PLUGIN_VERSION, serverUrl) + buildFile.text
settingsFile.text = maybeAddPluginsToSettings(gradleVersion, 'com.gradle.develocity', DEVELOCITY_PLUGIN_VERSION, CCUD_PLUGIN_VERSION, serverUrl) + settingsFile.text
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, 'com.gradle.develocity', DEVELOCITY_PLUGIN_VERSION, CCUD_PLUGIN_VERSION, serverUrl) + buildFile.text
}

String maybeAddPluginsToSettings(GradleVersion gradleVersion, boolean legacy, String ccudPluginVersion, URI serverUri) {
String maybeAddPluginsToSettings(GradleVersion gradleVersion, String pluginId, String pluginVersion, String ccudPluginVersion, URI serverUri) {
if (gradleVersion < GradleVersion.version('6.0')) {
'' // applied in build.gradle
} else {
configuredPlugin(gradleVersion, legacy, ccudPluginVersion, serverUri)
configuredPlugin(pluginId, pluginVersion, ccudPluginVersion, serverUri)
}
}

String maybeAddPluginsToRootProject(GradleVersion gradleVersion, boolean legacy, String ccudPluginVersion, URI serverUrl) {
String maybeAddPluginsToRootProject(GradleVersion gradleVersion, String pluginId, String pluginVersion, String ccudPluginVersion, URI serverUrl) {
if (gradleVersion < GradleVersion.version('5.0')) {
"""
plugins {
Expand All @@ -161,26 +207,23 @@ abstract class BaseInitScriptTest extends Specification {
}
"""
} else if (gradleVersion < GradleVersion.version('6.0')) {
configuredPlugin(gradleVersion, legacy, ccudPluginVersion, serverUrl)
configuredPlugin(pluginId, pluginVersion, ccudPluginVersion, serverUrl)
} else {
'' // applied in settings.gradle
}
}

String configuredPlugin(GradleVersion gradleVersion, boolean legacy, String ccudPluginVersion, URI serverUri) {
def pluginId = legacy
? (gradleVersion < GradleVersion.version('6.0') ? 'com.gradle.build-scan' : 'com.gradle.enterprise')
: 'com.gradle.develocity'
def pluginVersion = legacy ? "3.16.2" : DEVELOCITY_PLUGIN_VERSION
def configBlock = legacy ? 'gradleEnterprise' : 'develocity'
"""
String configuredPlugin(String pluginId, String pluginVersion, String ccudPluginVersion, URI serverUri) {
def configBlock = GradleVersion.version(pluginVersion) >= GradleVersion.version('3.17') ? 'develocity'
: (pluginId == 'com.gradle.enterprise' ? 'gradleEnterprise' : 'buildScan')
"""
plugins {
id '$pluginId' version '$pluginVersion'
${ccudPluginVersion ? "id 'com.gradle.common-custom-user-data-gradle-plugin' version '$ccudPluginVersion'" : ""}
}
$configBlock {
server = '$serverUri'
${legacy ? "buildScan { publishAlways() }" : ""}
${configBlock != 'develocity' ? "buildScan { publishAlways() }" : ""}
}
"""
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/com/gradle/TestDevelocityInjection.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class TestDevelocityInjection extends BaseInitScriptTest {
@Requires({data.testGradleVersion.compatibleWithCurrentJvm})
def "enforces Develocity URL and allowUntrustedServer in project if enforce url parameter is enabled"() {
given:
declareDevelocityPluginApplication(testGradleVersion.gradleVersion, URI.create('https://develocity-server.invalid'))
declarePluginApplication(testGradleVersion.gradleVersion, pluginId, pluginVersion, URI.create('https://develocity-server.invalid'))

when:
def config = testConfig().withServer(mockScansServer.address, true)
Expand All @@ -198,7 +198,7 @@ class TestDevelocityInjection extends BaseInitScriptTest {
outputContainsBuildScanUrl(result)

where:
testGradleVersion << ALL_VERSIONS
[testGradleVersion, pluginId, pluginVersion] << ALL_PLUGIN_VERSIONS
}

@Requires({data.testGradleVersion.compatibleWithCurrentJvm})
Expand Down

0 comments on commit ab12111

Please sign in to comment.