Skip to content

Commit 325efe4

Browse files
committed
Feat: Script for Coverage check #22
- Added script for CI for test coverage Signed-off-by: Tanryberdi <[email protected]> See #22
1 parent 9728d69 commit 325efe4

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

.github/workflows/test.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,21 @@ jobs:
1515
- name: Checkout Code
1616
uses: actions/[email protected]
1717
- name: Unit Tests
18-
run: go test -v -race ./...
18+
run: |
19+
sudo go test ./... -coverprofile coverage.out -covermode count
20+
sudo go tool cover -func coverage.out
21+
- name: Quality Gate - Test coverage shall be above threshold
22+
env:
23+
TESTCOVERAGE_THRESHOLD: 75
24+
run: |
25+
echo "Quality Gate: checking test coverage is above threshold ..."
26+
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
27+
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
28+
echo "Current test coverage : $totalCoverage %"
29+
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
30+
echo "OK"
31+
else
32+
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
33+
echo "Failed"
34+
exit 1
35+
fi

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ lint:
55
test:
66
@echo "Testing ..."
77
@go clean -testcache
8-
@go test -v -race -coverprofile cover.out ./...
9-
@go tool cover -func=cover.out
8+
@go test -v -race -coverprofile coverage.out ./...
9+
@go tool cover -func=coverage.out

0 commit comments

Comments
 (0)