Migrate x-pack core module to new testing framework (#125740)

This commit is contained in:
Mark Vieira 2025-03-27 10:13:29 -07:00 committed by GitHub
parent 4fa41062a6
commit 0c50403ebb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 82 additions and 14 deletions

View file

@ -36,7 +36,6 @@ public abstract class RestrictedBuildApiService implements BuildService<Restrict
map.put(LegacyRestTestBasePlugin.class, ":qa:remote-clusters");
map.put(LegacyRestTestBasePlugin.class, ":qa:repository-multi-version");
map.put(LegacyRestTestBasePlugin.class, ":qa:rolling-upgrade-legacy");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:core");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ent-search");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:fleet");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:logstash");

View file

@ -12,9 +12,9 @@ import java.nio.file.Paths
apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.publish'
apply plugin: 'elasticsearch.internal-cluster-test'
apply plugin: 'elasticsearch.legacy-yaml-rest-test'
apply plugin: 'elasticsearch.legacy-java-rest-test'
apply plugin: 'elasticsearch.legacy-yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-test-artifact'
base {
@ -149,16 +149,8 @@ restResources {
}
}
testClusters.configureEach {
testDistribution = 'default'
setting 'xpack.security.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial'
//disabling ILM history as it disturbs testDSXpackUsage test
setting 'indices.lifecycle.history_index_enabled', 'false'
keystore 'bootstrap.password', 'x-pack-test-password'
user username: "x_pack_rest_user", password: "x-pack-test-password"
requiresFeature 'es.failure_store_feature_flag_enabled', Version.fromString("8.15.0")
systemProperty 'es.queryable_built_in_roles_enabled', 'false'
tasks.named("javaRestTest") {
usesDefaultDistribution("uses the _xpack api")
}
if (buildParams.snapshotBuild == false) {

View file

@ -13,10 +13,14 @@ import org.elasticsearch.cluster.metadata.DataStreamFailureStoreSettings;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.junit.ClassRule;
import java.util.List;
import java.util.Map;
@ -27,6 +31,18 @@ import static org.hamcrest.Matchers.notNullValue;
public class DataStreamRestIT extends ESRestTestCase {
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.setting("xpack.security.enabled", "true")
.setting("xpack.license.self_generated.type", "trial")
.setting("indices.lifecycle.history_index_enabled", "false")
.feature(FeatureFlag.FAILURE_STORE_ENABLED)
.keystore("bootstrap.password", "x-pack-test-password")
.user("x_pack_rest_user", "x-pack-test-password")
.systemProperty("es.queryable_built_in_roles_enabled", "false")
.build();
private static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password"));
@Override
@ -143,4 +159,9 @@ public class DataStreamRestIT extends ESRestTestCase {
throw new RuntimeException(e);
}
}
@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}

View file

@ -18,11 +18,14 @@ import org.elasticsearch.core.TimeValue;
import org.elasticsearch.license.License;
import org.elasticsearch.license.LicenseSettings;
import org.elasticsearch.license.TestUtils;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.junit.Before;
import org.junit.ClassRule;
import java.io.IOException;
import java.util.Locale;
@ -39,6 +42,16 @@ import static org.hamcrest.Matchers.equalTo;
*/
public class LicenseInstallationIT extends ESRestTestCase {
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.setting("xpack.security.enabled", "true")
.setting("xpack.license.self_generated.type", "trial")
.feature(FeatureFlag.FAILURE_STORE_ENABLED)
.keystore("bootstrap.password", "x-pack-test-password")
.user("x_pack_rest_user", "x-pack-test-password")
.systemProperty("es.queryable_built_in_roles_enabled", "false")
.build();
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password".toCharArray()));
@ -159,4 +172,9 @@ public class LicenseInstallationIT extends ESRestTestCase {
assertThat("the cluster should be using a trial license", innerMap.get("type"), equalTo("trial"));
});
}
@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}

View file

@ -12,12 +12,27 @@ import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.ClassRule;
import static org.hamcrest.Matchers.is;
public class StackTemplatesRestIT extends ESRestTestCase {
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.setting("xpack.security.enabled", "true")
.setting("xpack.license.self_generated.type", "trial")
.feature(FeatureFlag.FAILURE_STORE_ENABLED)
.keystore("bootstrap.password", "x-pack-test-password")
.user("x_pack_rest_user", "x-pack-test-password")
.systemProperty("es.queryable_built_in_roles_enabled", "false")
.build();
private static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password"));
@Override
@ -56,4 +71,9 @@ public class StackTemplatesRestIT extends ESRestTestCase {
ResponseException exception = expectThrows(ResponseException.class, () -> client.performRequest(deleteRequest));
assertThat(exception.getResponse().getStatusLine().getStatusCode(), is(404));
}
@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}

View file

@ -13,11 +13,24 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.junit.ClassRule;
public class XPackCoreClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.setting("xpack.security.enabled", "true")
.setting("xpack.license.self_generated.type", "trial")
.feature(FeatureFlag.FAILURE_STORE_ENABLED)
.keystore("bootstrap.password", "x-pack-test-password")
.user("x_pack_rest_user", "x-pack-test-password")
.systemProperty("es.queryable_built_in_roles_enabled", "false")
.build();
private static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password"));
public XPackCoreClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
@ -33,4 +46,9 @@ public class XPackCoreClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
protected Settings restClientSettings() {
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", BASIC_AUTH_VALUE).build();
}
@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}