Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void testCurrentExamplePlugin() throws IOException {

GradleRunner.create()
.withProjectDir(tmpDir.getRoot())
.withTestKitDir(tmpDir.newFolder("testkit"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary. We are already running each of these test cases in a new temporary directory. By default TestKit is going to create a .gradle-test-kit directory under that folder. Really all this is doing is renaming that folder testkit instead. If the example plugin tests are failing, it's not due to testkit directory reuse.

.withArguments("clean", "check", "-s", "-i", "--warning-mode=all", "--scan")
.withPluginClasspath()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,35 @@

import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;


public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTestCase {

public static final String PROJECT_NAME = "elasticsearch-build-resources";

public void testUpToDateWithSourcesConfigured() {
GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
getGradleRunner(PROJECT_NAME)
.withArguments("clean", "-s")
.withPluginClasspath()
.build();

BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
BuildResult result = getGradleRunner(PROJECT_NAME)
.withArguments("buildResources", "-s", "-i")
.withPluginClasspath()
.build();
assertTaskSuccessful(result, ":buildResources");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml");

result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
result = getGradleRunner(PROJECT_NAME)
.withArguments("buildResources", "-s", "-i")
.withPluginClasspath()
.build();
assertTaskUpToDate(result, ":buildResources");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml");
}

public void testImplicitTaskDependencyCopy() {
BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
BuildResult result = getGradleRunner(PROJECT_NAME)
.withArguments("clean", "sampleCopyAll", "-s", "-i")
.withPluginClasspath()
.build();

assertTaskSuccessful(result, ":buildResources");
Expand All @@ -69,10 +60,8 @@ public void testImplicitTaskDependencyCopy() {
}

public void testImplicitTaskDependencyInputFileOfOther() {
BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
BuildResult result = getGradleRunner(PROJECT_NAME)
.withArguments("clean", "sample", "-s", "-i")
.withPluginClasspath()
.build();

assertTaskSuccessful(result, ":sample");
Expand All @@ -81,11 +70,12 @@ public void testImplicitTaskDependencyInputFileOfOther() {
}

public void testIncorrectUsage() {
BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir(PROJECT_NAME))
.withArguments("noConfigAfterExecution", "-s", "-i")
.withPluginClasspath()
.buildAndFail();
assertOutputContains("buildResources can't be configured after the task ran");
assertOutputContains(
getGradleRunner(PROJECT_NAME)
.withArguments("noConfigAfterExecution", "-s", "-i")
.buildAndFail()
.getOutput(),
"buildResources can't be configured after the task ran"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;

/*
* Licensed to Elasticsearch under one or more contributor
Expand All @@ -25,10 +24,8 @@
public class JarHellTaskIT extends GradleIntegrationTestCase {

public void testJarHellDetected() {
BuildResult result = GradleRunner.create()
.withProjectDir(getProjectDir("jarHell"))
BuildResult result = getGradleRunner("jarHell")
.withArguments("clean", "precommit", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath())
.withPluginClasspath()
.buildAndFail();

assertTaskFailed(result, ":jarHell");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand All @@ -16,6 +20,9 @@

public abstract class GradleIntegrationTestCase extends GradleUnitTestCase {

@Rule
public TemporaryFolder testkitTmpDir = new TemporaryFolder();

protected File getProjectDir(String name) {
File root = new File("src/testKit/");
if (root.exists() == false) {
Expand All @@ -26,9 +33,16 @@ protected File getProjectDir(String name) {
}

protected GradleRunner getGradleRunner(String sampleProject) {
File testkit;
try {
testkit = testkitTmpDir.newFolder();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return GradleRunner.create()
.withProjectDir(getProjectDir(sampleProject))
.withPluginClasspath();
.withPluginClasspath()
.withTestKitDir(testkit);
}

protected File getBuildDir(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.Before;

import java.util.Arrays;

public class TestClustersPluginIT extends GradleIntegrationTestCase {

private GradleRunner testclusters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this something more appropriate, like runner?


@Before
public void setUp() throws Exception {
testclusters = getGradleRunner("testclusters");
}

public void testListClusters() {
BuildResult result = getTestClustersRunner("listTestClusters").build();

Expand Down Expand Up @@ -187,10 +195,7 @@ private GradleRunner getTestClustersRunner(String... tasks) {
arguments[tasks.length] = "-s";
arguments[tasks.length + 1] = "-i";
arguments[tasks.length + 2] = "-Dlocal.repo.path=" + getLocalTestRepoPath();
return GradleRunner.create()
.withProjectDir(getProjectDir("testclusters"))
.withArguments(arguments)
.withPluginClasspath();
return testclusters.withArguments(arguments);
}

private void assertStartedAndStoppedOnce(BuildResult result, String nodeName) {
Expand Down