#!/bin/bash set -euo pipefail THRESHOLD="${1:-100}" PROFILE=$(mktemp) trap 'rm -f "$PROFILE"' EXIT go test -coverprofile="$PROFILE" -covermode=atomic ./... # Exclude main.go from coverage calculation (entrypoint, not unit-testable) COVERAGE=$(grep -v "main\.go:" "$PROFILE" | go tool cover -func=/dev/stdin | grep ^total: | awk '{print $3}' | tr -d '%') if awk "BEGIN{exit(!($COVERAGE < $THRESHOLD))}"; then echo "FAIL: coverage ${COVERAGE}% is below ${THRESHOLD}%" exit 1 fi echo "OK: coverage ${COVERAGE}% meets ${THRESHOLD}% threshold"