helidon-io / helidon

Java libraries for writing microservices
https://helidon.io
Apache License 2.0
3.53k stars 564 forks source link

AddConfigBlock doesn't override prod config #9410

Open danielkec opened 1 month ago

danielkec commented 1 month ago

Environment Details


Problem Description

When production config file exists, it is possible to override it with:

@AddConfig(key = "another.key", value = "test.value")

But @AddConfigBlock behaves differently and doesn't override existing properties.

Steps to reproduce

diff --git a/microprofile/tests/testing/junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestAddConfigBlockYaml.java b/microprofile/tests/testing/junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestAddConfigBlockYaml.java
--- a/microprofile/tests/testing/junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestAddConfigBlockYaml.java  (revision d47f53aea182799c1da5f1172b8acf289a24b3a8)
+++ b/microprofile/tests/testing/junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestAddConfigBlockYaml.java  (date 1729174260197)
@@ -29,6 +29,8 @@

 @HelidonTest
 @AddConfigBlock(type = "yaml", value = """
+    another:
+      key: "test.value"
     another1:
       key: "another1.value"
     another2:
@@ -36,6 +38,10 @@
 """)
 class TestAddConfigBlockYaml {

+    @Inject
+    @ConfigProperty(name = "another.key")
+    private String another;
+
     @Inject
     @ConfigProperty(name = "another1.key")
     private String another1;
@@ -46,6 +52,7 @@

     @Test
     void testValue() {
+        assertThat(another, is("test.value"));
         assertThat(another1, is("another1.value"));
         assertThat(another2, is("another2.value"));
     }

diff --git a/microprofile/tests/testing/junit5/src/main/resources/application.yaml b/microprofile/tests/testing/junit5/src/main/resources/application.yaml
new file mode 100644
--- /dev/null   (date 1729174221128)
+++ b/microprofile/tests/testing/junit5/src/main/resources/application.yaml (date 1729174221128)
@@ -0,0 +1,2 @@
+another:
+  key: "prod.value"
\ No newline at end of file

Result:

java.lang.AssertionError: 
Expected: is "test.value"
     but: was "prod.value"
Expected :test.value
Actual   :prod.value
<Click to see difference>

    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
    at io.helidon.microprofile.tests.testing.junit5.TestAddConfigBlockYaml.testValue(TestAddConfigBlockYaml.java:55)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
danielkec commented 1 month ago

Workaround is adding config_ordinal to the block:

@AddConfigBlock(type = "yaml", value = """
    config_ordinal: 205
    another:
      key: "test.value"