Skip to content

Make reuse of sql test code explicit #45884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions x-pack/plugin/sql/qa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ forbiddenApisMain {
thirdPartyAudit.enabled = false

subprojects {
apply plugin: 'elasticsearch.standalone-rest-test'
if (subprojects.isEmpty()) {
// leaf project
apply plugin: 'elasticsearch.standalone-rest-test'
} else {
apply plugin: 'elasticsearch.build'
}

configurations.testRuntimeClasspath {
resolutionStrategy.force "org.slf4j:slf4j-api:1.7.25"
}
dependencies {

/* Since we're a standalone rest test we actually get transitive
Expand All @@ -65,7 +74,8 @@ subprojects {

// H2GIS testing dependencies
testRuntime ("org.orbisgis:h2gis:${h2gisVersion}") {
exclude group: "org.locationtech.jts"
exclude group: "org.locationtech.jts"
exclude group: "com.fasterxml.jackson.core"
}

testRuntime project(path: xpackModule('sql:jdbc'), configuration: 'nodeps')
Expand Down
41 changes: 27 additions & 14 deletions x-pack/plugin/sql/qa/security/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

dependencies {
testCompile project(':x-pack:plugin:core')
}
Expand All @@ -6,27 +7,27 @@ Project mainProject = project

group = "${group}.x-pack.qa.sql.security"

configurations.create('testArtifacts')

TaskProvider testJar = tasks.register("testJar", Jar) {
appendix 'test'
from sourceSets.test.output
}

artifacts {
testArtifacts testJar
}

// Tests are pushed down to subprojects and will be checked there.
testingConventions.enabled = false

subprojects {
// Use resources from the parent project in subprojects
sourceSets {
test {
mainProject.sourceSets.test.output.classesDirs.each { dir ->
output.addClassesDir { dir }
output.builtBy(mainProject.tasks.testClasses)
}
runtimeClasspath += mainProject.sourceSets.test.output
}
}

processTestResources {
from mainProject.file('src/test/resources')
}
// Use tests from the root security qa project in subprojects
configurations.create('testArtifacts')

dependencies {
testCompile project(":x-pack:plugin:core")
testArtifacts project(path: mainProject.path, configuration: 'testArtifacts')
}

testClusters.integTest {
Expand All @@ -42,10 +43,22 @@ subprojects {
user username: "test_admin", password: "x-pack-test-password"
}

File testArtifactsDir = project.file("$buildDir/testArtifacts")
TaskProvider copyTestClasses = tasks.register("copyTestClasses", Copy) {
dependsOn configurations.testArtifacts
from { zipTree(configurations.testArtifacts.singleFile) }
into testArtifactsDir
}

integTest.runner {
dependsOn copyTestClasses
testClassesDirs += project.files(testArtifactsDir)
classpath += configurations.testArtifacts
nonInputProperties.systemProperty 'tests.audit.logfile',
"${ -> testClusters.integTest.singleNode().getAuditLog()}"
nonInputProperties.systemProperty 'tests.audit.yesterday.logfile',
"${ -> testClusters.integTest.singleNode().getAuditLog().getParentFile()}/integTest_audit-${new Date().format('yyyy-MM-dd')}.json"
}

testingConventions.enabled = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,9 @@ public void assertLogs() throws Exception {
assertThat(log.containsKey("user.name"), is(true));
List<String> indices = new ArrayList<>();
if (log.containsKey("indices")) {
indices = (ArrayList<String>) log.get("indices");
@SuppressWarnings("unchecked")
List<String> castIndices = (ArrayList<String>) log.get("indices");
indices = castIndices;
if ("test_admin".equals(log.get("user.name"))) {
/*
* Sometimes we accidentally sneak access to the security tables. This is fine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static List<URL> classpathResources(String pattern) throws Exception {
}
}
// normal file access
else {
else if (Files.isDirectory(path)) {
Files.walkFileTree(path, EnumSet.allOf(FileVisitOption.class), 1, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Expand Down