fix(tests): honor singular Helm test template overrides

Signed-off-by: Ahmed Kamal <email.ahmedkamal@googlemail.com>
Assisted-by: LLM
This commit is contained in:
Ahmed Kamal committed 2026-10-31 23:36:26 +02:00
1 parent a8c4640bea
commit 8d40fc8e00
2 files changed
+36 -1

No files matched your search

+33
View File
@@ -106,6 +106,7 @@ suite: assertion override
templates: [templates/single.yaml, templates/multi.yaml]
tests:
- it: checks only the single-document template
template: templates/multi.yaml
documentIndex: 0
asserts:
- template: templates/single.yaml
@@ -139,3 +140,35 @@ EOF
fi
grep -q 'resource_test.yaml:6: use documentSelector' output
}
@test "rejects a singular test template overriding a single-document suite" {
write_suite single
sed -i '/ - it:/a\ template: templates/multi.yaml' packages/apps/example/tests/resource_test.yaml
if python3 "$REPO_ROOT/hack/check-helm-document-indices.py" "$base" > output 2>&1; then
echo "accepted a positional selector on the test template override" >&2
false
fi
grep -q 'use documentSelector.*templates/multi.yaml' output
}
@test "allows a singular test template selecting one document" {
write_suite multi
sed -i '/ - it:/a\ template: templates/single.yaml' packages/apps/example/tests/resource_test.yaml
python3 "$REPO_ROOT/hack/check-helm-document-indices.py" "$base"
}
@test "plural test templates take precedence over the singular test template" {
write_suite multi
sed -i '/ - it:/a\ templates: [templates/single.yaml]\n template: templates/multi.yaml' packages/apps/example/tests/resource_test.yaml
python3 "$REPO_ROOT/hack/check-helm-document-indices.py" "$base"
}
@test "an empty plural test override falls back to the singular template" {
write_suite single
sed -i '/ - it:/a\ templates: []\n template: templates/multi.yaml' packages/apps/example/tests/resource_test.yaml
if python3 "$REPO_ROOT/hack/check-helm-document-indices.py" "$base" > output 2>&1; then
echo "accepted a positional selector after an empty plural override" >&2
false
fi
grep -q 'use documentSelector.*templates/multi.yaml' output
}
+3 -1
View File
@@ -50,7 +50,9 @@ def check(base):
if not suite:
continue
for test in suite.get("tests", []):
templates = test.get("templates", suite.get("templates", ["templates/*"]))
templates = test.get("templates") or (
[test["template"]] if test.get("template")
else suite.get("templates", ["templates/*"]))
for assertion in test.get("asserts", []):
index = assertion.get("documentIndex", test.get("documentIndex", {}))
number = index.get("line")