Skip to content

Commit 1b6c4ff

Browse files
committed
Organize repository-s3 tests in one project as test suites
1 parent b4bba12 commit 1b6c4ff

File tree

15 files changed

+95
-109
lines changed

15 files changed

+95
-109
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaBasePlugin.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
import org.gradle.api.artifacts.Configuration;
2424
import org.gradle.api.artifacts.ResolutionStrategy;
2525
import org.gradle.api.file.FileCollection;
26-
import org.gradle.api.plugins.JavaBasePlugin;
2726
import org.gradle.api.plugins.JavaPluginExtension;
27+
import org.gradle.api.plugins.JvmTestSuitePlugin;
28+
import org.gradle.api.plugins.jvm.JvmTestSuite;
2829
import org.gradle.api.provider.Provider;
2930
import org.gradle.api.tasks.SourceSet;
3031
import org.gradle.api.tasks.SourceSetContainer;
@@ -35,6 +36,7 @@
3536
import org.gradle.api.tasks.testing.Test;
3637
import org.gradle.jvm.toolchain.JavaLanguageVersion;
3738
import org.gradle.jvm.toolchain.JavaToolchainService;
39+
import org.gradle.testing.base.TestingExtension;
3840

3941
import java.util.List;
4042
import java.util.Map;
@@ -61,7 +63,9 @@ public void apply(Project project) {
6163
// make sure the global build info plugin is applied to the root project
6264
project.getRootProject().getPluginManager().apply(GlobalBuildInfoPlugin.class);
6365
buildParams = project.getRootProject().getExtensions().getByType(BuildParameterExtension.class);
64-
project.getPluginManager().apply(JavaBasePlugin.class);
66+
project.getPluginManager().apply(JvmTestSuitePlugin.class);
67+
TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
68+
testing.getSuites().withType(JvmTestSuite.class).configureEach(suite -> { suite.useJUnit(); });
6569
// common repositories setup
6670
project.getPluginManager().apply(RepositoriesSetupPlugin.class);
6771
project.getPluginManager().apply(ElasticsearchTestBasePlugin.class);

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ public RestTestBasePlugin(ProviderFactory providerFactory) {
100100
public void apply(Project project) {
101101
project.getPluginManager().apply(ElasticsearchJavaBasePlugin.class);
102102
project.getPluginManager().apply(InternalDistributionDownloadPlugin.class);
103-
project.getPluginManager().apply(JvmTestSuitePlugin.class);
104103

105104
var bwcVersions = loadBuildParams(project).get().getBwcVersions();
106105

build-tools/src/main/java/org/elasticsearch/gradle/util/GradleUtils.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.gradle.api.Task;
1515
import org.gradle.api.UnknownTaskException;
1616
import org.gradle.api.artifacts.Configuration;
17+
import org.gradle.api.artifacts.ExternalModuleDependency;
1718
import org.gradle.api.artifacts.ModuleDependency;
1819
import org.gradle.api.artifacts.ProjectDependency;
1920
import org.gradle.api.plugins.JavaBasePlugin;
@@ -196,11 +197,9 @@ public static boolean isModuleProject(String projectPath) {
196197
}
197198

198199
public static void disableTransitiveDependencies(Configuration config) {
199-
config.getDependencies().configureEach(dep -> {
200-
if (dep instanceof ModuleDependency
201-
&& dep instanceof ProjectDependency == false
202-
&& dep.getGroup().startsWith("org.elasticsearch") == false) {
203-
((ModuleDependency) dep).setTransitive(false);
200+
config.getDependencies().withType(ExternalModuleDependency.class).configureEach(dep -> {
201+
if (dep.getGroup().startsWith("org.elasticsearch") == false) {
202+
dep.setTransitive(false);
204203
}
205204
});
206205
}

modules/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
configure(subprojects.findAll { it.parent.path == project.path }) {
1111
group = 'org.elasticsearch.plugin' // for modules which publish client jars
12-
// apply plugin: 'elasticsearch.internal-testclusters'
1312
apply plugin: 'elasticsearch.internal-es-plugin'
1413
apply plugin: 'elasticsearch.internal-test-artifact'
1514

modules/repository-s3/build.gradle

+85-12
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99
org.elasticsearch.gradle.internal.test.rest.RestTestSuite
1010

11-
apply plugin: 'elasticsearch.internal-yaml-rest-test'
1211
apply plugin: 'elasticsearch.internal-cluster-test'
12+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
1313
apply plugin: 'elasticsearch.internal-java-rest-test'
1414

1515
esplugin {
@@ -41,27 +41,46 @@ dependencies {
4141
}
4242

4343
tasks.named('check') {
44+
// TODO revisit to be the default in ES
4445
dependsOn tasks.withType(Test)
4546
}
4647

47-
4848
testing {
4949
suites {
5050
configureEach {
51+
// common configuration for all test suites in this project
5152
dependencies {
53+
implementation project()
5254
implementation project(':test:framework')
53-
implementation project(':test:fixtures:s3-fixture')
54-
runtimeOnly "org.slf4j:slf4j-simple:${versions.slf4j}"
55+
runtimeOnly("org.slf4j:slf4j-simple:${versions.slf4j}") {
56+
// TODO: (Rene) this should be handled by ElasticsearchBase Plugin but there's an open issue with that.
57+
transitive = false
58+
}
59+
}
60+
}
61+
test {
62+
dependencies {
63+
println "adding dependency = dependency"
64+
implementation(project(':test:fixtures:s3-fixture'))
5565
}
5666
}
67+
// test suite defined by InternalJavaRestTestPlugin
5768
internalClusterTest {
5869
dependencies {
5970
implementation project(':test:fixtures:minio-fixture')
6071
}
72+
targets {
73+
all {
74+
testTask.configure {
75+
// TODO: remove once https://github.com/elastic/elasticsearch/issues/101608 is fixed
76+
systemProperty 'es.insecure_network_trace_enabled', 'true'
77+
}
78+
}
79+
}
6180
}
81+
// test suite for the java rest tests provided by the InternalJavaRestTestPlugin
6282
javaRestTest {
6383
dependencies {
64-
implementation project()
6584
implementation project(':test:fixtures:aws-fixture-utils')
6685
implementation project(':test:fixtures:s3-fixture')
6786
implementation project(':test:fixtures:testcontainer-utils')
@@ -71,6 +90,7 @@ testing {
7190
implementation project(':test:fixtures:testcontainer-utils')
7291
}
7392
}
93+
// test suite for the Yaml rest tests provided by the InternalYamlRestTestPlugin
7494
yamlRestTest {
7595
dependencies {
7696
implementation project()
@@ -79,7 +99,66 @@ testing {
7999
implementation project(':test:fixtures:testcontainer-utils')
80100
}
81101
}
82-
102+
// Add-hoc test suites require to be passed a type. (usually JvmTestSuite)
103+
webIdentityTokenTest(JvmTestSuite) {
104+
dependencies {
105+
implementation project(':server')
106+
}
107+
targets {
108+
all {
109+
testTask.configure {
110+
systemProperty 'es.allow_insecure_settings', 'true'
111+
}
112+
}
113+
}
114+
}
115+
insecureCredentialsTest(JvmTestSuite) {
116+
dependencies {
117+
implementation project(':server')
118+
}
119+
targets {
120+
all {
121+
testTask.configure {
122+
systemProperty 'es.allow_insecure_settings', 'true'
123+
}
124+
}
125+
}
126+
}
127+
s3ThirdPartyTest(JvmTestSuite) {
128+
dependencies {
129+
implementation project(':test:fixtures:minio-fixture')
130+
implementation project(':server')
131+
}
132+
targets {
133+
all {
134+
testTask.configure {
135+
boolean useFixture = false
136+
String s3PermanentAccessKey = System.getenv("amazon_s3_access_key")
137+
String s3PermanentSecretKey = System.getenv("amazon_s3_secret_key")
138+
String s3PermanentBucket = System.getenv("amazon_s3_bucket")
139+
String s3PermanentBasePath = System.getenv("amazon_s3_base_path")
140+
141+
// If all these variables are missing then we are testing against the MinIO fixture instead, which has the following credentials hard-coded in.
142+
if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3PermanentBasePath) {
143+
useFixture = true
144+
s3PermanentAccessKey = 's3_test_access_key'
145+
s3PermanentSecretKey = 's3_test_secret_key'
146+
s3PermanentBucket = 'bucket'
147+
s3PermanentBasePath = 'base_path'
148+
}
149+
println "useFixture = $useFixture"
150+
systemProperty("tests.use.fixture", Boolean.toString(useFixture))
151+
systemProperty 'test.s3.account', s3PermanentAccessKey
152+
systemProperty 'test.s3.key', s3PermanentSecretKey
153+
systemProperty 'test.s3.bucket', s3PermanentBucket
154+
nonInputProperties.systemProperty 'test.s3.base', s3PermanentBasePath + "_third_party_tests_" + buildParams.testSeed
155+
156+
// test container accesses ~/.testcontainers.properties read
157+
systemProperty "tests.security.manager", "false"
158+
}
159+
}
160+
}
161+
}
83162
}
84163
}
85164

@@ -100,12 +179,6 @@ esplugin.bundleSpec.from('config/repository-s3') {
100179
into 'config'
101180
}
102181

103-
tasks.named("internalClusterTest").configure {
104-
// TODO: remove once https://github.com/elastic/elasticsearch/issues/101608 is fixed
105-
systemProperty 'es.insecure_network_trace_enabled', 'true'
106-
}
107-
108-
109182
tasks.named("thirdPartyAudit").configure {
110183
ignoreMissingClasses(
111184
// classes are missing

modules/repository-s3/qa/build.gradle

-6
This file was deleted.

modules/repository-s3/qa/insecure-credentials/build.gradle

-18
This file was deleted.

modules/repository-s3/qa/third-party/build.gradle

-46
This file was deleted.

modules/repository-s3/qa/web-identity-token/build.gradle

-18
This file was deleted.

0 commit comments

Comments
 (0)