feat: improve Go test coverage script by adding trap for coverage file cleanup and ensuring readonly module mode

This commit is contained in:
Wikid82
2025-11-20 11:37:37 -05:00
parent 56ab9486a4
commit 4fcc0d6c4f
+3 -3
View File
@@ -6,9 +6,11 @@ BACKEND_DIR="$ROOT_DIR/backend"
COVERAGE_FILE="$BACKEND_DIR/coverage.pre-commit.out"
MIN_COVERAGE="${CPM_MIN_COVERAGE:-40}"
trap 'rm -f "$COVERAGE_FILE"' EXIT
cd "$BACKEND_DIR"
go test -coverprofile="$COVERAGE_FILE" ./internal/...
go test -mod=readonly -coverprofile="$COVERAGE_FILE" ./internal/...
go tool cover -func="$COVERAGE_FILE" | tail -n 1
TOTAL_LINE=$(go tool cover -func="$COVERAGE_FILE" | grep total)
@@ -30,6 +32,4 @@ if total < minimum:
sys.exit(1)
PY
rm -f "$COVERAGE_FILE"
echo "Coverage requirement met"