fix(ecs): emit empty arrays for empty mountPoints and volumesFrom (#9015)

* fix(ecs): emit empty arrays for empty mountPoints and volumesFrom
* test(ecs): an omitted volumesFrom reads back as [] too
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-11-19 18:37:38 -04:00
1 parent c1e7b240ea
commit dca36665b5
3 files changed
+52 -4

No files matched your search

@@ -141,4 +141,48 @@ class EcsJsonHandlerCommandEntryPointTest {
field + " must read back as an empty array");
}
}
@Test
void emptyMountPointsAndVolumesFromReadBackAsEmptyArrays() throws Exception {
String requestJson = """
{
"family": "empty-mount-family",
"containerDefinitions": [
{
"name": "app",
"image": "alpine:latest",
"mountPoints": [],
"volumesFrom": []
}
]
}
""";
JsonNode request = objectMapper.readTree(requestJson);
Response response = handler.handle("RegisterTaskDefinition", request, "us-east-1");
JsonNode container = objectMapper.valueToTree(response.getEntity())
.path("taskDefinition").path("containerDefinitions").get(0);
for (String field : List.of("mountPoints", "volumesFrom")) {
JsonNode value = container.path(field);
assertTrue(value.isArray() && value.isEmpty(),
field + " must read back as an empty array");
}
String omitted = """
{
"family": "absent-mount-family",
"containerDefinitions": [
{"name": "app", "image": "alpine:latest"}
]
}
""";
Response absent = handler.handle("RegisterTaskDefinition", objectMapper.readTree(omitted), "us-east-1");
JsonNode plain = objectMapper.valueToTree(absent.getEntity())
.path("taskDefinition").path("containerDefinitions").get(0);
assertTrue(plain.path("mountPoints").isArray() && plain.path("mountPoints").isEmpty(),
"an omitted mountPoints reads back as an empty array");
assertTrue(plain.path("volumesFrom").isArray() && plain.path("volumesFrom").isEmpty(),
"an omitted volumesFrom reads back as an empty array");
}
}
@@ -75,7 +75,7 @@ class EcsJsonHandlerVolumesFromTest {
}
@Test
void containerDefinitionOmitsVolumesFromWhenNotProvided() throws Exception {
void containerDefinitionReadsBackAnEmptyVolumesFromWhenNotProvided() throws Exception {
JsonNode request = objectMapper.readTree("""
{
"family": "plain-family",
@@ -89,6 +89,10 @@ class EcsJsonHandlerVolumesFromTest {
JsonNode app = objectMapper.valueToTree(response.getEntity())
.path("taskDefinition").path("containerDefinitions").get(0);
assertTrue(app.path("volumesFrom").isMissingNode());
// The parser always sets volumesFrom, and the register-task-definition guide example
// carries it back as [] for a container without one, so an omitted field reads back as
// an empty array rather than staying absent.
JsonNode volumesFrom = app.path("volumesFrom");
assertTrue(volumesFrom.isArray() && volumesFrom.isEmpty());
}
}