Convert enterprise search module to new testing framework (#125807)

This commit is contained in:
Mark Vieira 2025-03-28 09:07:00 -07:00 committed by GitHub
parent 7a0de676ad
commit 3ac0c136aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
61 changed files with 73 additions and 56 deletions

View file

@ -1,6 +1,8 @@
apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.internal-cluster-test'
apply plugin: 'elasticsearch.legacy-java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
esplugin {
name = 'x-pack-ent-search'
@ -35,25 +37,50 @@ dependencies {
javaRestTestImplementation(project(path: xpackModule('core')))
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
javaRestTestImplementation(project(':modules:lang-mustache'))
yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
}
testClusters.configureEach {
testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'true'
setting 'xpack.security.autoconfiguration.enabled', 'false'
user username: 'x_pack_rest_user', password: 'x-pack-test-password'
restResources {
restApi {
include '_common',
'bulk',
'cluster',
'connector',
'nodes',
'indices',
'index',
'query_rules',
'search_application',
'xpack',
'security',
'search',
'ml'
}
}
tasks.named("dependencyLicenses").configure {
tasks.named("dependencyLicenses") {
mapping from: /jackson.*/, to: 'jackson'
}
tasks.named("thirdPartyAudit").configure {
tasks.named("thirdPartyAudit") {
ignoreMissingClasses(
// [missing classes] SLF4j includes an optional class that depends on an extension class (!)
'org.slf4j.ext.EventData'
)
}
tasks.named("yamlRestTest") {
usesDefaultDistribution("uses the xpack/usage api")
}
tasks.named("yamlRestCompatTestTransform") { task ->
// Behavioral Analytics is deprecated with 9.0.0.
task.addAllowedWarning("Behavioral Analytics is deprecated and will be removed in a future release.")
}
addQaCheckDependencies(project)
artifacts {
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
}

View file

@ -1,47 +0,0 @@
apply plugin: 'elasticsearch.legacy-yaml-rest-test'
apply plugin: 'elasticsearch.legacy-yaml-rest-compat-test'
dependencies {
yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
}
restResources {
restApi {
include '_common',
'bulk',
'cluster',
'connector',
'nodes',
'indices',
'index',
'query_rules',
'search_application',
'xpack',
'security',
'search',
'ml'
}
}
testClusters.configureEach {
testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial'
extraConfigFile 'roles.yml', file('roles.yml')
user username: 'entsearch-superuser', password: 'entsearch-superuser-password', role: 'superuser'
user username: 'entsearch-admin', password: 'entsearch-admin-password', role: 'admin'
user username: 'entsearch-user', password: 'entsearch-user-password', role: 'user'
user username: 'entsearch-unprivileged', password: 'entsearch-unprivileged-password', role: 'unprivileged'
}
artifacts {
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
}
tasks.named("yamlRestCompatTestTransform").configure(
{ task ->
// Behavioral Analytics is deprecated with 9.0.0.
task.addAllowedWarning("Behavioral Analytics is deprecated and will be removed in a future release.")
}
)

View file

@ -16,10 +16,12 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.test.SecuritySettingsSourceField;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.junit.ClassRule;
import java.io.IOException;
import java.util.Map;
@ -28,6 +30,14 @@ import static org.hamcrest.Matchers.is;
public class ConnectorSecretsSystemIndexIT extends ESRestTestCase {
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.module("x-pack-ent-search")
.setting("xpack.security.enabled", "true")
.setting("xpack.security.autoconfiguration.enabled", "false")
.user("x_pack_rest_user", "x-pack-test-password")
.build();
static final String BASIC_AUTH_VALUE = basicAuthHeaderValue(
"x_pack_rest_user",
SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING
@ -91,4 +101,9 @@ public class ConnectorSecretsSystemIndexIT extends ESRestTestCase {
private Map<String, Object> getResponseMap(Response response) throws IOException {
return XContentHelper.convertToMap(XContentType.JSON.xContent(), EntityUtils.toString(response.getEntity()), false);
}
@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}

View file

@ -12,11 +12,28 @@ 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.local.distribution.DistributionType;
import org.elasticsearch.test.cluster.util.resource.Resource;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.junit.ClassRule;
public class EnterpriseSearchRestIT extends ESClientYamlSuiteTestCase {
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.setting("xpack.security.enabled", "true")
.setting("xpack.security.autoconfiguration.enabled", "false")
.setting("xpack.license.self_generated.type", "trial")
.rolesFile(Resource.fromClasspath("roles.yml"))
.user("entsearch-superuser", "entsearch-superuser-password", "superuser", false)
.user("entsearch-admin", "entsearch-admin-password", "admin", false)
.user("entsearch-user", "entsearch-user-password", "user", false)
.user("entsearch-unprivileged", "entsearch-unprivileged-password", "unprivileged", false)
.build();
public EnterpriseSearchRestIT(final ClientYamlTestCandidate testCandidate) {
super(testCandidate);
}
@ -37,4 +54,9 @@ public class EnterpriseSearchRestIT extends ESClientYamlSuiteTestCase {
final String value = basicAuthHeaderValue("entsearch-admin", new SecureString("entsearch-admin-password".toCharArray()));
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", value).build();
}
@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}

View file

@ -26,7 +26,7 @@ dependencies {
freeCompatTests project(path: ':rest-api-spec', configuration: 'restCompatTests')
platinumTests project(path: ':x-pack:plugin', configuration: 'restXpackTests')
platinumTests project(path: ':x-pack:plugin:eql:qa:rest', configuration: 'restXpackTests')
platinumTests project(path: ':x-pack:plugin:ent-search:qa:rest', configuration: 'restXpackTests')
platinumTests project(path: ':x-pack:plugin:ent-search', configuration: 'restXpackTests')
platinumCompatTests project(path: ':x-pack:plugin', configuration: 'restCompatTests')
platinumCompatTests project(path: ':x-pack:plugin:eql:qa:rest', configuration: 'restCompatTests')
}