Skip to content
Merged
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
13 changes: 8 additions & 5 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,26 @@ if command -v staticcheck &>/dev/null; then
fi
fi

# Tests with race detection
# Tests with race detection and coverage (combined; -race requires -covermode=atomic)
echo "Running tests..."
if ! go test ./... -race -count=1 -timeout 120s; then
if ! go test ./... -race -count=1 -coverprofile=coverage.out -covermode=atomic -timeout 120s; then
FAILED=1
fi

# Coverage threshold (80%)
# Coverage threshold (50%)
echo "Checking coverage..."
go test ./... -count=1 -coverprofile=coverage.out -covermode=atomic -timeout 120s
COVERAGE=$(go tool cover -func=coverage.out 2>/dev/null | grep total | awk '{print $3}' | sed 's/%//')
if [ -n "$COVERAGE" ]; then
if (( $(echo "$COVERAGE < 50" | bc -l) )); then
COVERAGE_INT=$(awk -v c="$COVERAGE" 'BEGIN { printf "%d", c * 100 }')
if [ "$COVERAGE_INT" -lt 5000 ]; then
echo "Coverage ${COVERAGE}% is below 50% threshold"
FAILED=1
else
echo "Coverage: ${COVERAGE}%"
fi
else
echo "Coverage collection failed (no total in coverage.out)"
FAILED=1
fi
rm -f coverage.out

Expand Down
Loading