Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(core): let a native host path follow a configured persistent path (#5777)

Hector Venturaf897dfc3b6db
diff --git a/src/main/java/io/github/hectorvent/floci/config/HostDefaultsConfigSource.java b/src/main/java/io/github/hectorvent/floci/config/HostDefaultsConfigSource.java
index 36104964ec..f20b43be3b 100644
--- a/src/main/java/io/github/hectorvent/floci/config/HostDefaultsConfigSource.java
+++ b/src/main/java/io/github/hectorvent/floci/config/HostDefaultsConfigSource.java
@@ -20,6 +20,7 @@ public class HostDefaultsConfigSource implements ConfigSource {
static final int ORDINAL = 260;
static final String PERSISTENT_PATH = "floci.storage.persistent-path";
static final String HOST_PERSISTENT_PATH = "floci.storage.host-persistent-path";
+ static final String FOLLOW_PERSISTENT_PATH = "${" + PERSISTENT_PATH + "}";
private final Map<String, String> properties;
@@ -30,8 +31,9 @@ public class HostDefaultsConfigSource implements ConfigSource {
HostDefaultsConfigSource(boolean nativeOnHost) {
if (nativeOnHost) {
String dir = HostDataDir.persistentPathDefault();
- // The binary and Docker share the host filesystem, so child containers bind the same path.
- this.properties = Map.of(PERSISTENT_PATH, dir, HOST_PERSISTENT_PATH, dir);
+ // The binary and Docker share the host filesystem, so child containers bind the same path,
+ // including one the user sets in config/application.yml.
+ this.properties = Map.of(PERSISTENT_PATH, dir, HOST_PERSISTENT_PATH, FOLLOW_PERSISTENT_PATH);
} else {
this.properties = Map.of();
}
diff --git a/src/test/java/io/github/hectorvent/floci/config/HostDefaultsConfigSourceTest.java b/src/test/java/io/github/hectorvent/floci/config/HostDefaultsConfigSourceTest.java
index 14c0ca93bd..a63476a807 100644
--- a/src/test/java/io/github/hectorvent/floci/config/HostDefaultsConfigSourceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/config/HostDefaultsConfigSourceTest.java
@@ -1,7 +1,13 @@
package io.github.hectorvent.floci.config;
+import io.smallrye.config.PropertiesConfigSource;
+import io.smallrye.config.SmallRyeConfig;
+import io.smallrye.config.SmallRyeConfigBuilder;
+import org.eclipse.microprofile.config.spi.ConfigSource;
import org.junit.jupiter.api.Test;
+import java.util.Map;
+
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.allOf;
@@ -27,8 +33,28 @@ class HostDefaultsConfigSourceTest {
@Test
void nativeHostRunSetsBothPathsToTheSameDirectory() {
HostDefaultsConfigSource source = new HostDefaultsConfigSource(true);
+ SmallRyeConfig config = configWith(source);
String dir = source.getValue(HostDefaultsConfigSource.PERSISTENT_PATH);
- assertThat(source.getValue(HostDefaultsConfigSource.HOST_PERSISTENT_PATH), equalTo(dir));
+ assertThat(config.getValue(HostDefaultsConfigSource.PERSISTENT_PATH, String.class), equalTo(dir));
+ assertThat(config.getValue(HostDefaultsConfigSource.HOST_PERSISTENT_PATH, String.class), equalTo(dir));
+ }
+
+ @Test
+ void hostPathFollowsAPersistentPathTheUserConfigures() {
+ SmallRyeConfig config = configWith(new HostDefaultsConfigSource(true),
+ new PropertiesConfigSource(Map.of(HostDefaultsConfigSource.PERSISTENT_PATH, "/srv/floci"),
+ "config/application.yml", 265));
+ assertThat(config.getValue(HostDefaultsConfigSource.HOST_PERSISTENT_PATH, String.class),
+ equalTo("/srv/floci"));
+ }
+
+ @Test
+ void anExplicitHostPathStillWins() {
+ SmallRyeConfig config = configWith(new HostDefaultsConfigSource(true),
+ new PropertiesConfigSource(Map.of(HostDefaultsConfigSource.PERSISTENT_PATH, "/srv/floci",
+ HostDefaultsConfigSource.HOST_PERSISTENT_PATH, "/mnt/floci"), "env", 300));
+ assertThat(config.getValue(HostDefaultsConfigSource.HOST_PERSISTENT_PATH, String.class),
+ equalTo("/mnt/floci"));
}
@Test
@@ -36,4 +62,9 @@ class HostDefaultsConfigSourceTest {
// classpath application.yml is 255, config/application.yml in the working directory 265.
assertThat(new HostDefaultsConfigSource(false).getOrdinal(), allOf(greaterThan(255), lessThan(265)));
}
+
+ private static SmallRyeConfig configWith(ConfigSource... sources) {
+ // The default interceptors expand ${...} expressions, as the runtime config does.
+ return new SmallRyeConfigBuilder().addDefaultInterceptors().withSources(sources).build();
+ }
}