Skip to content

Commit

Permalink
ci: added coverage to go lang tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevkevinpal committed Dec 6, 2023
1 parent 359a216 commit 811d397
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/prjob_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions cover-check.sh
Original file line number Diff line number Diff line change
@@ -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 } }'

0 comments on commit 811d397

Please sign in to comment.