test(config): accept declared YAML configuration expressions (#6477)

* test(config): accept declared YAML configuration expressions

Recognize nonempty YAML enabled declarations before expression resolution, while preserving rejection of missing, null and blank declarations.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

* test(config): reject container nodes as toggle declarations

Reject YAML objects and arrays in the enabled declaration coverage guard while preserving scalar expression handling. Cover empty mappings and sequences alongside missing, null and blank declarations.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

---------

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-25 07:09:52 -04:00
1 parent edbcac33c7
commit 4f9866418f
1 file changed
+28 -1
@@ -11,6 +11,7 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -38,7 +39,7 @@ class ServiceConfigYamlCoverageTest {
continue;
}
String key = StringUtil.skewer(accessor.getName());
if (!services.path(key).path("enabled").isBoolean()) {
if (!declaresEnabled(services.path(key))) {
missing.add(config + " -> floci.services." + key + ".enabled");
}
}
@@ -50,6 +51,32 @@ class ServiceConfigYamlCoverageTest {
+ "not count, since it binds to nothing. Missing: " + missing);
}
@Test
void explicitBooleanAndEnvironmentExpressionDeclareTheToggle() throws IOException {
for (String value : List.of("true", "false", "${FLOCI_SERVICES_RESOURCE_GROUPS_ENABLED:true}")) {
JsonNode service = new YAMLMapper().readTree("enabled: " + value);
assertTrue(declaresEnabled(service), value);
}
}
@Test
void missingBareNullAndEmptyDeclarationsRemainMissing() throws IOException {
for (String yaml : List.of("{}", "service:", "service: {}", "service: {enabled: null}",
"service: {enabled: ''}", "service: {enabled: ' '}",
"service: {enabled: {}}", "service: {enabled: []}")) {
JsonNode service = new YAMLMapper().readTree(yaml).path("service");
assertFalse(declaresEnabled(service), yaml);
}
}
private static boolean declaresEnabled(JsonNode service) {
JsonNode enabled = service.path("enabled");
// Config binding validates Boolean values after resolving expressions. This guard only
// checks that the YAML declares a value instead of relying on the interface fallback.
return enabled.isValueNode() && !enabled.isNull()
&& (!enabled.isTextual() || !enabled.textValue().isBlank());
}
/**
* Config records without an {@code enabled()} toggle (for example {@code DuckConfig},
* which only carries an image and an optional URL) are not services that can be turned