Skip to content

Instantly share code, notes, and snippets.

@uudashr
Last active June 17, 2020 04:59
Show Gist options
  • Save uudashr/5996ff83c810c925c289344b728df0cf to your computer and use it in GitHub Desktop.
Save uudashr/5996ff83c810c925c289344b728df0cf to your computer and use it in GitHub Desktop.
Golang coverage check, limit to min threshold
#!/bin/sh
# Ref:
# - https://pretzelhands.com/posts/command-line-flags
# Usage:
# go test -race -v -coverprofile=coverage.out
# ./cover-check.sh coverage.out 70
PROFILE=$1
THRESHOLD=$2
COVERAGE=$(go tool cover -func=$PROFILE|grep total|awk '{print substr($3, 1, length($3) - 1)}')
echo "$COVERAGE $THRESHOLD" | awk '{if (!($1 >= $2)) { print "Coverage: " $1 "%" ", Expected threshold: " $2 "%"; exit 1 } }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment