diff --git a/.github/workflows/pre-main.yml b/.github/workflows/pre-main.yml index 732c0cc..d62ba30 100644 --- a/.github/workflows/pre-main.yml +++ b/.github/workflows/pre-main.yml @@ -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 diff --git a/Makefile b/Makefile index 1807062..fdac79b 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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