Make sure the clean task doesn't break test fixtures (#43641)

Use a dedicated fixture dir.
This commit is contained in:
Alpar Torok 2019-07-08 17:49:33 +03:00
parent 299a52c17d
commit 0c8294e633
5 changed files with 30 additions and 9 deletions

3
.gitignore vendored
View File

@ -41,3 +41,6 @@ html_docs
# random old stuff that we should look at the necessity of...
/tmp/
eclipse-build
# projects using testfixtures
testfixtures_shared/

View File

@ -35,6 +35,9 @@ import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.testing.Test;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.function.BiConsumer;
@ -50,6 +53,10 @@ public class TestFixturesPlugin implements Plugin<Project> {
"testFixtures", TestFixtureExtension.class, project
);
ExtraPropertiesExtension ext = project.getExtensions().getByType(ExtraPropertiesExtension.class);
File testfixturesDir = project.file("testfixtures_shared");
ext.set("testFixturesDir", testfixturesDir);
if (project.file(DOCKER_COMPOSE_YML).exists()) {
// convenience boilerplate with build plugin
// Can't reference tasks that are implemented in Groovy, use reflection instead
@ -63,6 +70,14 @@ public class TestFixturesPlugin implements Plugin<Project> {
Task buildFixture = project.getTasks().create("buildFixture");
Task pullFixture = project.getTasks().create("pullFixture");
Task preProcessFixture = project.getTasks().create("preProcessFixture");
preProcessFixture.doFirst((task) -> {
try {
Files.createDirectories(testfixturesDir.toPath());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
preProcessFixture.getOutputs().dir(testfixturesDir);
buildFixture.dependsOn(preProcessFixture);
pullFixture.dependsOn(preProcessFixture);
Task postProcessFixture = project.getTasks().create("postProcessFixture");
@ -90,6 +105,9 @@ public class TestFixturesPlugin implements Plugin<Project> {
pullFixture.dependsOn(tasks.getByName("composePull"));
tasks.getByName("composeUp").mustRunAfter(preProcessFixture);
tasks.getByName("composePull").mustRunAfter(preProcessFixture);
tasks.getByName("composeDown").doLast((task) -> {
project.delete(testfixturesDir);
});
configureServiceInfoForTask(
postProcessFixture,

View File

@ -6,4 +6,4 @@ services:
dockerfile: Dockerfile
ports:
- "9000"
command: ["server", "/minio/data"]
command: ["server", "/minio/data"]

View File

@ -29,14 +29,14 @@ List<String> services = ["peppa", "hdfs"]
preProcessFixture.doLast {
// We need to create these up-front because if docker creates them they will be owned by root and we won't be
// able to clean them up
services.each { file("${buildDir}/shared/${it}").mkdirs() }
services.each { file("${testFixturesDir}/shared/${it}").mkdirs() }
}
postProcessFixture {
inputs.dir("${buildDir}/shared")
inputs.dir("${testFixturesDir}/shared")
services.each { service ->
File confTemplate = file("${buildDir}/shared/${service}/krb5.conf.template")
File confFile = file("${buildDir}/shared/${service}/krb5.conf")
File confTemplate = file("${testFixturesDir}/shared/${service}/krb5.conf.template")
File confFile = file("${testFixturesDir}/shared/${service}/krb5.conf")
outputs.file(confFile)
doLast {
assert confTemplate.exists()
@ -47,7 +47,7 @@ postProcessFixture {
}
}
project.ext.krb5Conf = { service -> file("$buildDir/shared/${service}/krb5.conf") }
project.ext.krb5Keytabs = { service, fileName -> file("$buildDir/shared/${service}/keytabs/${fileName}") }
project.ext.krb5Conf = { service -> file("$testFixturesDir/shared/${service}/krb5.conf") }
project.ext.krb5Keytabs = { service, fileName -> file("$testFixturesDir/shared/${service}/keytabs/${fileName}") }
test.enabled = false

View File

@ -7,7 +7,7 @@ services:
dockerfile: Dockerfile
command: "bash /fixture/src/main/resources/provision/peppa.sh"
volumes:
- ./build/shared/peppa:/fixture/build
- ./testfixtures_shared/shared/peppa:/fixture/build
# containers have bad entropy so mount /dev/urandom. Less secure but this is a test fixture.
- /dev/urandom:/dev/random
ports:
@ -20,7 +20,7 @@ services:
dockerfile: Dockerfile
command: "bash /fixture/src/main/resources/provision/hdfs.sh"
volumes:
- ./build/shared/hdfs:/fixture/build
- ./testfixtures_shared/shared/hdfs:/fixture/build
# containers have bad entropy so mount /dev/urandom. Less secure but this is a test fixture.
- /dev/urandom:/dev/random
ports: