Skip to content

Commit

Permalink
Add unit test coverage gate; coverage-html make path
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Dec 21, 2021
1 parent 5b34061 commit f7e0ff7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/pre-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ jobs:

- name: Run Tests
run: make generate-golang-schema build tests

- name: Quality Gate - Test coverage shall be above threshold
env:
TESTCOVERAGE_THRESHOLD: 60
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
totalCoverage=`go tool cover -func=cover.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
echo "OK"
else
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
echo "Failed"
exit 1
fi
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ GO_PACKAGES=$(shell go list ./... | grep -v vendor)
generate-golang-schema \
lint \
tests \
coverage-html \
vet

all: generate-golang-schema fmt lint build tests
Expand All @@ -26,6 +27,9 @@ lint:
tests:
go test -coverprofile=cover.out ./...

coverage-html: tests
go tool cover -html cover.out

validate-example:
jsonschema -i schemas/claim.example.json schemas/claim.schema.json

Expand Down

0 comments on commit f7e0ff7

Please sign in to comment.