Skip to content

Commit

Permalink
Make sure the clean task doesn't break test fixtures (#43641)
Browse files Browse the repository at this point in the history
Use a dedicated fixture dir.
  • Loading branch information
alpar-t committed Jul 8, 2019
1 parent 299a52c commit 0c8294e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
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;

Expand All @@ -50,6 +53,10 @@ public void apply(Project 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
Expand All @@ -63,6 +70,14 @@ public void apply(Project 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");
Expand Down Expand Up @@ -90,6 +105,9 @@ public void apply(Project 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,
Expand Down
2 changes: 1 addition & 1 deletion plugins/repository-s3/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ services:
dockerfile: Dockerfile
ports:
- "9000"
command: ["server", "/minio/data"]
command: ["server", "/minio/data"]
12 changes: 6 additions & 6 deletions test/fixtures/krb5kdc-fixture/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
4 changes: 2 additions & 2 deletions test/fixtures/krb5kdc-fixture/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 0c8294e

Please sign in to comment.