diff --git a/.github/workflows/prjob_tests.yml b/.github/workflows/prjob_tests.yml index a135a7c19..35af68188 100644 --- a/.github/workflows/prjob_tests.yml +++ b/.github/workflows/prjob_tests.yml @@ -38,5 +38,7 @@ jobs: - ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Install cover + run: go get golang.org/x/tools/cmd/cover - name: Tests - run: go test ./config ./auth ./db ./handlers ./routes ./utils + run: go test ./config ./auth ./db ./handlers ./routes ./utils -race -v -coverprofile=coverage.out && ./cover-check.sh coverage.out 2.9 diff --git a/cover-check.sh b/cover-check.sh new file mode 100755 index 000000000..67e6501ca --- /dev/null +++ b/cover-check.sh @@ -0,0 +1,14 @@ +#!/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 } }'