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.
This commit is contained in:
Stefan Kalscheuer 2018-02-04 20:04:47 +01:00
parent 38a7d4952d
commit b2082925d5
2 changed files with 12 additions and 4 deletions

View File

@ -131,5 +131,11 @@
<version>2.13.0</version> <version>2.13.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -36,6 +36,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.apache.commons.io.FileUtils.copyDirectory;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.is; 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. * Requires "vault" binary to be in current user's executable path. Not using MLock, so no extended rights required.
*/ */
@BeforeEach @BeforeEach
public void setUp(TestInfo testInfo) throws VaultConnectorException { public void setUp(TestInfo testInfo) throws VaultConnectorException, IOException {
/* Determine, if TLS is required */ /* Determine, if TLS is required */
boolean isTls = testInfo.getTags().contains("tls"); boolean isTls = testInfo.getTags().contains("tls");
@ -960,14 +961,15 @@ public class HTTPVaultConnectorTest {
* @return Vault Configuration * @return Vault Configuration
* @throws IllegalStateException on error * @throws IllegalStateException on error
*/ */
private VaultConfiguration initializeVault(boolean tls) throws IllegalStateException { private VaultConfiguration initializeVault(boolean tls) throws IllegalStateException, IOException {
String dataResource = getClass().getResource("/data_dir").getPath(); File dataDir = tmpDir.newFolder();
copyDirectory(new File(getClass().getResource("/data_dir").getPath()), dataDir);
/* Generate vault local unencrypted configuration */ /* Generate vault local unencrypted configuration */
VaultConfiguration config = new VaultConfiguration() VaultConfiguration config = new VaultConfiguration()
.withHost("localhost") .withHost("localhost")
.withPort(getFreePort()) .withPort(getFreePort())
.withDataLocation(dataResource) .withDataLocation(dataDir.toPath())
.disableMlock(); .disableMlock();
/* Enable TLS with custom certificate and key, if required */ /* Enable TLS with custom certificate and key, if required */