Skip to content

running normal go test without verbose, only log if failing #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 41 additions & 5 deletions scripts/evergreen/unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,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