From 8c4637d62981b23820926f12badfa72a2952efaf Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Mon, 17 Feb 2025 15:37:48 -0300 Subject: [PATCH] tests/k8s: print tests report Added 'report-tests' command to gha-run.sh to print to stdout a report of the tests executed. For example: ``` SUMMARY (2025-02-17-14:43:53): Pass: 0 Fail: 1 STATUSES: not_ok foo.bats OUTPUTS: ::group::foo.bats 1..3 not ok 1 test 1 not ok 2 test 2 ok 3 test 3 1..2 not ok 1 test 1 not ok 2 test 2 ::endgroup:: ``` Signed-off-by: Wainer dos Santos Moschetta --- tests/integration/kubernetes/gha-run.sh | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/integration/kubernetes/gha-run.sh b/tests/integration/kubernetes/gha-run.sh index cbdff162e8..7149545ee5 100755 --- a/tests/integration/kubernetes/gha-run.sh +++ b/tests/integration/kubernetes/gha-run.sh @@ -294,6 +294,49 @@ function run_tests() { popd } +# Print a report about tests executed. +# +# Crawl over the output files found on each "reports/yyyy-mm-dd-hh:mm:ss" +# directory. +# +function report_tests() { + local reports_dir="${kubernetes_dir}/reports" + local ok + local not_ok + local status + + if [[ ! -d "${reports_dir}" ]]; then + info "no reports directory found: ${reports_dir}" + return + fi + + for report_dir in "${reports_dir}"/*; do + mapfile -t ok < <(find "${report_dir}" -name "ok-*.out") + mapfile -t not_ok < <(find "${report_dir}" -name "not_ok-*.out") + + cat <<-EOF + SUMMARY ($(basename "${report_dir}")): + Pass: ${#ok[*]} + Fail: ${#not_ok[*]} + EOF + + echo -e "\nSTATUSES:" + for out in "${not_ok[@]}" "${ok[@]}"; do + status=$(basename "${out}" | cut -d '-' -f1) + bats=$(basename "${out}" | cut -d '-' -f2- | sed 's/.out$//') + echo " ${status} ${bats}" + done + + echo -e "\nOUTPUTS:" + for out in "${not_ok[@]}" "${ok[@]}"; do + bats=$(basename "${out}" | cut -d '-' -f2- | sed 's/.out$//') + echo "::group::${bats}" + cat "${out}" + echo "::endgroup::" + done + done +} + function collect_artifacts() { if [[ -z "${start_time:-}" ]]; then warn "tests start time is not defined. Cannot gather journal information" @@ -547,6 +590,7 @@ function main() { deploy-kata-garm) deploy_kata "garm" ;; deploy-kata-zvsi) deploy_kata "zvsi" ;; deploy-snapshotter) deploy_snapshotter ;; + report-tests) report_tests ;; run-tests) run_tests ;; run-tests-kcli) run_tests "kcli" ;; collect-artifacts) collect_artifacts ;;