Introduce `qa` subprojects of `:modules:repository-s3` (#126274)

Today we have some special-case test classes in `:modules:repository-s3`
within the same source root as the regular tests, with some trickery to
define separate Gradle tasks to run them with their special-case
configs. This commit simplifies the build by just moving each of these
classes into its own Gradle project.
This commit is contained in:
David Turner 2025-04-04 11:29:05 +01:00 committed by GitHub
parent 88996bc01d
commit 7402dfdf65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 88 additions and 63 deletions

View File

@ -78,58 +78,11 @@ esplugin.bundleSpec.from('config/repository-s3') {
into 'config'
}
def testRepositoryCreds = tasks.register("testRepositoryCreds", Test) {
include '**/RepositoryCredentialsTests.class'
systemProperty 'es.allow_insecure_settings', 'true'
classpath = sourceSets.test.runtimeClasspath
testClassesDirs = sourceSets.test.output.classesDirs
}
tasks.named('test').configure {
// this is tested explicitly in separate test tasks
exclude '**/RepositoryCredentialsTests.class'
}
boolean useFixture = false
String s3PermanentAccessKey = System.getenv("amazon_s3_access_key")
String s3PermanentSecretKey = System.getenv("amazon_s3_secret_key")
String s3PermanentBucket = System.getenv("amazon_s3_bucket")
String s3PermanentBasePath = System.getenv("amazon_s3_base_path")
// If all these variables are missing then we are testing against the internal fixture instead, which has the following credentials hard-coded in.
if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3PermanentBasePath) {
useFixture = true
s3PermanentAccessKey = 's3_test_access_key'
s3PermanentSecretKey = 's3_test_secret_key'
s3PermanentBucket = 'bucket'
s3PermanentBasePath = 'base_path'
}
tasks.named("internalClusterTest").configure {
// this is tested explicitly in a separate test task
exclude '**/S3RepositoryThirdPartyTests.class'
// TODO: remove once https://github.com/elastic/elasticsearch/issues/101608 is fixed
systemProperty 'es.insecure_network_trace_enabled', 'true'
}
// 3rd Party Tests, i.e. testing against a real S3 repository
tasks.register("s3ThirdPartyTest", Test) {
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
SourceSet internalTestSourceSet = sourceSets.getByName(InternalClusterTestPlugin.SOURCE_SET_NAME)
setTestClassesDirs(internalTestSourceSet.getOutput().getClassesDirs())
setClasspath(internalTestSourceSet.getRuntimeClasspath())
include '**/S3RepositoryThirdPartyTests.class'
systemProperty("tests.use.fixture", Boolean.toString(useFixture))
systemProperty 'test.s3.account', s3PermanentAccessKey
systemProperty 'test.s3.key', s3PermanentSecretKey
systemProperty 'test.s3.bucket', s3PermanentBucket
nonInputProperties.systemProperty 'test.s3.base', s3PermanentBasePath + "_third_party_tests_" + buildParams.testSeed
// test container accesses ~/.testcontainers.properties read
systemProperty "tests.security.manager", "false"
}
tasks.named("thirdPartyAudit").configure {
ignoreMissingClasses(
// classes are missing
@ -152,9 +105,3 @@ tasks.named("thirdPartyAudit").configure {
'javax.activation.DataHandler'
)
}
tasks.named("check").configure {
dependsOn(tasks.withType(Test))
dependsOn(testRepositoryCreds)
}

View File

@ -0,0 +1,6 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

View File

@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
apply plugin: 'elasticsearch.java'
dependencies {
testImplementation project(':modules:repository-s3')
testImplementation project(':test:framework')
testImplementation project(':server')
}
tasks.named("test").configure {
systemProperty 'es.allow_insecure_settings', 'true'
}

View File

@ -32,8 +32,6 @@ import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.rest.FakeRestRequest;
import org.elasticsearch.watcher.ResourceWatcherService;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@ -51,14 +49,6 @@ import static org.hamcrest.Matchers.notNullValue;
@SuppressForbidden(reason = "test requires to set a System property to allow insecure settings when running in IDE")
public class RepositoryCredentialsTests extends ESSingleNodeTestCase {
static {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
// required for client settings overwriting when running in IDE
System.setProperty("es.allow_insecure_settings", "true");
return null;
});
}
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return List.of(ProxyS3RepositoryPlugin.class);

View File

@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
apply plugin: 'elasticsearch.java'
dependencies {
testImplementation project(':modules:repository-s3')
testImplementation project(':test:fixtures:minio-fixture')
testImplementation project(':test:framework')
testImplementation project(':server')
}
boolean useFixture = false
String s3PermanentAccessKey = System.getenv("amazon_s3_access_key")
String s3PermanentSecretKey = System.getenv("amazon_s3_secret_key")
String s3PermanentBucket = System.getenv("amazon_s3_bucket")
String s3PermanentBasePath = System.getenv("amazon_s3_base_path")
// If all these variables are missing then we are testing against the MinIO fixture instead, which has the following credentials hard-coded in.
if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3PermanentBasePath) {
useFixture = true
s3PermanentAccessKey = 's3_test_access_key'
s3PermanentSecretKey = 's3_test_secret_key'
s3PermanentBucket = 'bucket'
s3PermanentBasePath = 'base_path'
}
tasks.named("test").configure {
systemProperty("tests.use.fixture", Boolean.toString(useFixture))
systemProperty 'test.s3.account', s3PermanentAccessKey
systemProperty 'test.s3.key', s3PermanentSecretKey
systemProperty 'test.s3.bucket', s3PermanentBucket
nonInputProperties.systemProperty 'test.s3.base', s3PermanentBasePath + "_third_party_tests_" + buildParams.testSeed
// test container accesses ~/.testcontainers.properties read
systemProperty "tests.security.manager", "false"
}
tasks.register("s3ThirdPartyTest") {
dependsOn "test"
}

View File

@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
apply plugin: 'elasticsearch.java'
dependencies {
testImplementation project(':modules:repository-s3')
testImplementation project(':test:framework')
testImplementation project(':server')
}
tasks.named("test").configure {
systemProperty 'es.allow_insecure_settings', 'true'
}