Skip to content

Commit

Permalink
Updating enrich rest tests to run in new test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
masseyke committed Oct 16, 2023
1 parent 9358381 commit 440c760
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugin/enrich/qa/common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
apply plugin: 'elasticsearch.java'


dependencies {
api project(':test:framework')
}

dependencies {
api project(path: ':test:test-clusters')
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.junit.After;
import org.junit.ClassRule;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -36,6 +41,33 @@ public abstract class CommonEnrichRestTestCase extends ESRestTestCase {

private List<String> cleanupPipelines = new ArrayList<>();

@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.setting("xpack.security.enabled", "true")
.setting("xpack.watcher.enabled", "false")
.setting("xpack.monitoring.collection.enabled", "true")
.user("test_enrich", "x-pack-test-password")
.user("test_admin", "x-pack-test-password")
.build();

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}

@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("test_enrich", new SecureString("x-pack-test-password".toCharArray()));
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
}

@Override
protected Settings restAdminSettings() {
String token = basicAuthHeaderValue("test_admin", new SecureString("x-pack-test-password".toCharArray()));
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
}

/**
* Registers a pipeline for subsequent post-test clean up (i.e. DELETE),
* see {@link CommonEnrichRestTestCase#deletePipelinesAndPolicies()}.
Expand Down
14 changes: 11 additions & 3 deletions x-pack/plugin/enrich/qa/rest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'elasticsearch.legacy-java-rest-test'
apply plugin: 'elasticsearch.legacy-yaml-rest-test'
apply plugin: 'elasticsearch.legacy-yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-test-artifact'


import org.elasticsearch.gradle.Version
Expand All @@ -19,6 +20,13 @@ dependencies {
javaRestTestImplementation project(path: xpackModule('enrich:qa:common'))
}

tasks.named('yamlRestTest') {
usesDefaultDistribution()
}
tasks.named('javaRestTest') {
usesDefaultDistribution()
}

if (BuildParams.inFipsJvm){
// This test cluster is using a BASIC license and FIPS 140 mode is not supported in BASIC
tasks.named("javaRestTest").configure{enabled = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@

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.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.junit.ClassRule;

public class EnrichRestIT extends ESClientYamlSuiteTestCase {

Expand All @@ -23,4 +29,23 @@ public static Iterable<Object[]> parameters() throws Exception {
return createParameters();
}

private static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password"));

@Override
protected Settings restClientSettings() {
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", BASIC_AUTH_VALUE).build();
}

@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.setting("xpack.security.enabled", "true")
.user("x_pack_rest_user", "x-pack-test-password")
.build();

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}

}

0 comments on commit 440c760

Please sign in to comment.