Last active
June 17, 2020 04:59
-
-
Save uudashr/5996ff83c810c925c289344b728df0cf to your computer and use it in GitHub Desktop.
Golang coverage check, limit to min threshold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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