diff --git a/Makefile b/Makefile index 9c45c1c3b..938037f67 100644 --- a/Makefile +++ b/Makefile @@ -280,8 +280,9 @@ ENVTEST_ASSETS_DIR=$(shell pwd)/testbin golang-tests: scripts/evergreen/unit-tests.sh +# this will be used by the CI, evergreen requires -v to be able to parse the test-result golang-tests-race: - USE_RACE=true scripts/evergreen/unit-tests.sh + VERBOSE=true USE_RACE=true scripts/evergreen/unit-tests.sh sbom-tests: @ scripts/evergreen/run_python.sh -m pytest generate_ssdlc_report_test.py diff --git a/scripts/evergreen/unit-tests.sh b/scripts/evergreen/unit-tests.sh index 60fb081a4..1af0c46d6 100755 --- a/scripts/evergreen/unit-tests.sh +++ b/scripts/evergreen/unit-tests.sh @@ -11,13 +11,49 @@ find . -name go.mod -not -path "./docker/mongodb-kubernetes-tests/*" -exec dirna cd "$0" echo "testing $0" rm -f result.suite + +# Set verbose flag if VERBOSE is enabled +VERBOSE_FLAG="" +if [ "$VERBOSE" = "true" ]; then + VERBOSE_FLAG="-v" +fi + +RACE_FLAG="" if [ "$USE_RACE" = "true" ]; then - echo "running test with race enabled" - GO_TEST_CMD="go test -v -coverprofile cover.out \$(go list ./... | grep -v \"mongodb-community-operator/test/e2e\")" -else - echo "running test without race enabled" - GO_TEST_CMD="go test -v -coverprofile cover.out \$(go list ./... | grep -v \"mongodb-community-operator/test/e2e\")" + RACE_FLAG="-race" fi + +GO_TEST_CMD="go test $VERBOSE_FLAG $RACE_FLAG -coverprofile cover.out \$(go list ./... | grep -v \"mongodb-community-operator/test/e2e\")" echo "running $GO_TEST_CMD" eval "$GO_TEST_CMD" | tee -a result.suite ' + +# Capture the exit status from the test runs +EXIT_STATUS=$? + +# Generate summary of failed tests +echo "" +echo "=========================================" +echo "TEST SUMMARY" +echo "=========================================" + +FAILED_TESTS=$(find . -name "result.suite" -not -path "./docker/mongodb-kubernetes-tests/*" -exec grep -l "FAIL" {} \; 2>/dev/null || true) + +if [ -n "$FAILED_TESTS" ]; then + echo "FAILED TEST MODULES:" + for suite in $FAILED_TESTS; do + MODULE_DIR=$(dirname "$suite") + echo " - $MODULE_DIR" + echo " Failed tests:" + grep "^--- FAIL:" "$suite" | sed 's/^/ /' || true + done + echo "" + echo "Total modules with failures: $(echo "$FAILED_TESTS" | wc -l | tr -d ' ')" +else + echo " All tests passed!" +fi + +echo "=========================================" + +# Exit with the original status to preserve CI behavior +exit $EXIT_STATUS