From b2082925d504193e22b6c8f65c927360642f401b Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Sun, 4 Feb 2018 20:04:47 +0100 Subject: [PATCH] Copy Vault data directory to temp location before each test To avoid the annoying clean before each test run (because Vault data has been modified by previous run), the data is now copied from resource directory to temporary location. --- pom.xml | 6 ++++++ .../jvault/connector/HTTPVaultConnectorTest.java | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 47dc4fa..07a17dd 100644 --- a/pom.xml +++ b/pom.xml @@ -131,5 +131,11 @@ 2.13.0 test + + commons-io + commons-io + 2.6 + test + diff --git a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java index 98920a2..5b4f33e 100644 --- a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java +++ b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java @@ -36,6 +36,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import static org.apache.commons.io.FileUtils.copyDirectory; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.hamcrest.core.Is.is; @@ -84,7 +85,7 @@ public class HTTPVaultConnectorTest { * Requires "vault" binary to be in current user's executable path. Not using MLock, so no extended rights required. */ @BeforeEach - public void setUp(TestInfo testInfo) throws VaultConnectorException { + public void setUp(TestInfo testInfo) throws VaultConnectorException, IOException { /* Determine, if TLS is required */ boolean isTls = testInfo.getTags().contains("tls"); @@ -960,14 +961,15 @@ public class HTTPVaultConnectorTest { * @return Vault Configuration * @throws IllegalStateException on error */ - private VaultConfiguration initializeVault(boolean tls) throws IllegalStateException { - String dataResource = getClass().getResource("/data_dir").getPath(); + private VaultConfiguration initializeVault(boolean tls) throws IllegalStateException, IOException { + File dataDir = tmpDir.newFolder(); + copyDirectory(new File(getClass().getResource("/data_dir").getPath()), dataDir); /* Generate vault local unencrypted configuration */ VaultConfiguration config = new VaultConfiguration() .withHost("localhost") .withPort(getFreePort()) - .withDataLocation(dataResource) + .withDataLocation(dataDir.toPath()) .disableMlock(); /* Enable TLS with custom certificate and key, if required */