diff --git a/.github/scripts/run_chart_tests.py b/.github/scripts/run_chart_tests.py index 4568624..04a3f7d 100755 --- a/.github/scripts/run_chart_tests.py +++ b/.github/scripts/run_chart_tests.py @@ -23,9 +23,11 @@ - Checks if helm-unittest plugin is installed - If not installed, runs: helm plugin install (does not require Makefile) - Finds all directories under charts/ containing Chart.yaml - - For each chart directory with a Makefile, runs: make -C tests + - For each chart directory with a Makefile, runs: make -C test-all + (when defined) or `make tests` (legacy fallback) — `test-all` exercises the + parent-recursive suite AND each subchart standalone, catching helper/value + divergence that the parent-only run masks - Skips charts without a Makefile (e.g., library charts with no tests) - - Subcharts are tested through their parent chart's test suite REQUIREMENTS: - helm CLI must be installed @@ -91,8 +93,15 @@ def main(): skipped_charts.append(chart_dir) continue - print(f"Running helm chart tests in {chart_dir}...") - test_result = subprocess.run(["make", "-C", chart_dir, "tests"]) + # Prefer `test-all` (parent + standalone subcharts) when the chart's Makefile defines + # it; fall back to legacy `tests` target for charts that haven't adopted it yet. + makefile_targets = subprocess.run( + ["make", "-C", chart_dir, "-pn"], capture_output=True, text=True + ).stdout + target = "test-all" if "\ntest-all:" in makefile_targets else "tests" + + print(f"Running helm chart tests in {chart_dir} (target: {target})...") + test_result = subprocess.run(["make", "-C", chart_dir, target]) if test_result.returncode != 0: print(f"Helm chart tests failed in {chart_dir}.") failed_charts.append(chart_dir) diff --git a/charts/platform/Makefile b/charts/platform/Makefile index c90fac2..8172bba 100644 --- a/charts/platform/Makefile +++ b/charts/platform/Makefile @@ -1,4 +1,4 @@ -.PHONY: test tests unittests unittests-no-build debug check-unittest-plugin install-unittest-plugin clean-deps clean-subchart-packages rebuild-deps rebuild-deps-and-unpack rebuild-deps-force help +.PHONY: test tests unittests unittests-no-build debug check-unittest-plugin install-unittest-plugin clean-deps clean-subchart-packages rebuild-deps rebuild-deps-and-unpack rebuild-deps-force unittests-standalone test-all help # Run tests (with external dependencies rebuild) - DEFAULT behavior test: unittests @@ -6,12 +6,20 @@ tests: test test-no-build: unittests-no-build tests-no-build: test-no-build +# Run BOTH the parent's recursive test suite AND each standalone-installable subchart's +# tests rendered with that subchart's own values/helpers (matching how a customer would +# install it on its own). Catches helper / values divergence that the parent-recursive +# run silently masks. +test-all: unittests unittests-standalone + help: @echo "Seqera Platform Helm Chart - Available Make Targets" @echo "" @echo "Testing:" @echo " make test - Rebuild all Platform dependencies and run tests (DEFAULT)" @echo " make test-no-build - Run tests without rebuilding dependencies" + @echo " make test-all - Run parent-recursive tests AND each subchart standalone" + @echo " make unittests-standalone - Run each subchart's tests standalone (no parent context)" @echo " make debug - Run tests in debug mode" @echo " make unittests-update-snapshots - Rebuild all Platform dependencies and update snapshots" @echo "" @@ -119,6 +127,34 @@ unittests: rebuild-deps @echo "Running unit tests..." @helm unittest . +# Run each subchart's unit tests STANDALONE — i.e. invoke `helm unittest` from inside the +# subchart directory so its templates render with its own values.yaml / helpers, not under +# the parent's merged context. A subchart is considered "standalone-installable" if it ships +# its own `tests/` directory. +# +# This complements `unittests`: the parent-recursive run exercises the full integrated +# deployment, this target exercises each subchart as if a customer installed it on its own. +unittests-standalone: rebuild-deps + @echo "Running unit tests for each standalone-installable subchart..." + @failed=""; \ + for subchart_dir in charts/*/; do \ + subchart=$$(basename $$subchart_dir); \ + if [ ! -d "$$subchart_dir/tests" ]; then \ + echo "→ skipping $$subchart (no tests/ directory)"; \ + continue; \ + fi; \ + echo ""; \ + echo "→ $$subchart (standalone)"; \ + (cd "$$subchart_dir" && helm unittest .) || failed="$$failed $$subchart"; \ + done; \ + if [ -n "$$failed" ]; then \ + echo ""; \ + echo "✗ standalone tests failed for:$$failed"; \ + exit 1; \ + fi; \ + echo ""; \ + echo "✓ all standalone subchart tests passed" + unittests-update-snapshots: rebuild-deps @echo "Running unit tests and updating snapshots..." @helm unittest -u .