29 lines
711 B
Bash
29 lines
711 B
Bash
|
|
#!/bin/bash
|
||
|
|
# Check test coverage against minimum threshold
|
||
|
|
|
||
|
|
set -e
|
||
|
|
|
||
|
|
COVERAGE_FILE="${1:-.build/coverage.out}"
|
||
|
|
MIN_COVERAGE="${2:-80}"
|
||
|
|
|
||
|
|
if [ ! -f "$COVERAGE_FILE" ]; then
|
||
|
|
echo "Error: Coverage file not found: $COVERAGE_FILE"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Extract coverage percentage using awk
|
||
|
|
COVERAGE=$(go tool cover -func "$COVERAGE_FILE" | awk '/^total:/ { match($0, /[0-9.]+%/); print substr($0, RSTART, RLENGTH-1) }')
|
||
|
|
|
||
|
|
echo "Total coverage: ${COVERAGE}%"
|
||
|
|
|
||
|
|
# Compare as integers (remove decimals for simpler comparison)
|
||
|
|
COVERAGE_INT=${COVERAGE%.*}
|
||
|
|
|
||
|
|
if [ "$COVERAGE_INT" -lt "$MIN_COVERAGE" ]; then
|
||
|
|
echo "Coverage ${COVERAGE}% is below minimum ${MIN_COVERAGE}%"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "Coverage check passed"
|
||
|
|
exit 0
|