Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
119 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/test/groovy/hudson/plugins/gradle/AbstractIntegrationTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package hudson.plugins.gradle | ||
|
||
import org.junit.Rule | ||
import org.junit.rules.RuleChain | ||
import org.jvnet.hudson.test.JenkinsRule | ||
import spock.lang.Specification | ||
|
||
class AbstractIntegrationTest extends Specification { | ||
final JenkinsRule j = new JenkinsRule() | ||
final GradleInstallationRule gradleInstallationRule = new GradleInstallationRule(j) | ||
@Rule | ||
This comment has been minimized.
Sorry, something went wrong. |
||
public final RuleChain rules = RuleChain.outerRule(j).around(gradleInstallationRule) | ||
|
||
Map getDefaults() { | ||
[gradleName: gradleInstallationRule.gradleVersion, useWorkspaceAsHome: true, switches: '--no-daemon'] | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/test/groovy/hudson/plugins/gradle/BuildScanIntegrationTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package hudson.plugins.gradle | ||
|
||
import hudson.model.FreeStyleProject | ||
import org.jvnet.hudson.test.CreateFileBuilder | ||
|
||
class BuildScanIntegrationTest extends AbstractIntegrationTest { | ||
def 'build scan is discovered'() { | ||
given: | ||
gradleInstallationRule.addInstallation() | ||
FreeStyleProject p = j.createFreeStyleProject() | ||
p.buildersList.add(new CreateFileBuilder("build.gradle", """ | ||
plugins { | ||
id 'com.gradle.build-scan' version '1.6' | ||
} | ||
buildScan { | ||
licenseAgreementUrl = 'https://gradle.com/terms-of-service' | ||
licenseAgree = 'yes' | ||
} | ||
task hello << { println 'Hello' }""")) | ||
p.buildersList.add(new Gradle(tasks: 'hello', *: defaults, switches: '-Dscan --no-daemon')) | ||
|
||
when: | ||
def build = j.buildAndAssertSuccess(p) | ||
|
||
then: | ||
def action = build.getAction(BuildScanAction) | ||
action.scanUrl.contains('gradle.com') | ||
new URL(action.scanUrl) | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/groovy/hudson/plugins/gradle/CliIntegrationTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package hudson.plugins.gradle | ||
|
||
import hudson.cli.CLICommandInvoker | ||
import net.sf.json.JSON | ||
import net.sf.json.JSONArray | ||
import net.sf.json.JSONObject | ||
|
||
class CliIntegrationTest extends AbstractIntegrationTest { | ||
def 'list installations through CLI'() { | ||
when: | ||
CLICommandInvoker.Result result = new CLICommandInvoker(j, "get-gradle").invoke() | ||
|
||
then: | ||
assertCLIResult(result, '{}') | ||
|
||
when: | ||
gradleInstallationRule.addInstallations("inst1") | ||
result = new CLICommandInvoker(j, "get-gradle").invoke() | ||
|
||
then: | ||
assertCLIResult(result, expectedOutputForVersion('{"inst1":["%s"]}')) | ||
|
||
when: | ||
gradleInstallationRule.addInstallations("inst1", "inst2") | ||
result = new CLICommandInvoker(j, "get-gradle").invoke() | ||
|
||
then: | ||
assertCLIResult(result, expectedOutputForVersion('{"inst1":["%s"],"inst2":["%s"]}')) | ||
|
||
when: | ||
result = new CLICommandInvoker(j, "get-gradle").invokeWithArgs("--name=inst1") | ||
|
||
then: | ||
assertCLIResult(result, expectedOutputForVersion('["%s"]')) | ||
|
||
when: | ||
result = new CLICommandInvoker(j, "get-gradle").invokeWithArgs("--name=unknown") | ||
|
||
then: | ||
assertCLIError(result, 'Requested gradle installation not found: unknown') | ||
} | ||
|
||
private static void assertCLIResult(CLICommandInvoker.Result result, String expectedOutput) { | ||
assert result.returnCode() == 0 | ||
|
||
JSON expectedJson, resultJson | ||
|
||
if (expectedOutput.startsWith("[")) { | ||
expectedJson = JSONArray.fromObject(expectedOutput) | ||
resultJson = JSONArray.fromObject(result.stdout().trim()) | ||
} else { | ||
expectedJson = JSONObject.fromObject(expectedOutput) | ||
resultJson = JSONObject.fromObject(result.stdout().trim()) | ||
} | ||
|
||
assert resultJson == expectedJson | ||
} | ||
|
||
private static void assertCLIError(CLICommandInvoker.Result result, String expectedOutput) { | ||
assert result.returnCode() == 1 | ||
assert result.stderr().trim() == expectedOutput | ||
} | ||
|
||
private String expectedOutputForVersion(String output) { | ||
return String.format(output, gradleInstallationRule.gradleVersion, gradleInstallationRule.gradleVersion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi @wolfs, I was wondering why tests are taking so long to run (locally about 30min).
Then I found out that some tests are data-driven, testing many data points (e.g.
GradlePluginIntegrationTest
).For each single test a new Jenkins instance is started (due to this
@Rule
) and for all the tests that are really using Gradle inside a Jenkins job, a complete Gradle installation is downloaded. I guess overall that's many hundred MBs if not GB. So there is room for improvement here.