Skip to content

Instantly share code, notes, and snippets.

@jacygao
Created September 21, 2020 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacygao/716f47f60f685c5df3aea0e096886ba9 to your computer and use it in GitHub Desktop.
Save jacygao/716f47f60f685c5df3aea0e096886ba9 to your computer and use it in GitHub Desktop.
Go Code Coverage
#!/bin/bash
MIN_COVER=67.5
go test ./... -coverprofile cover.out
CODE_COVER=$( go tool cover -func=cover.out | tail -1 | sed '/^$/d;s/[[:blank:]]//g' | sed 's/total:(statements)//g' | sed 's/%//g' )
rm -rf cover.out
if [[ "${CODE_COVER}" < "${MIN_COVER}" ]]
then
echo "*** CODE COVERAGE CHECK FAILED, EXEPECTED ${MIN_COVER}%, GOT ${CODE_COVER}% ***"
exit 1
fi
echo "*** CODE COVERAGE PASSED AT: ${CODE_COVER}% ***"
go vet ./...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment