Skip to content

Commit 9dd9271

Browse files
committed
feat(backend ci): run unit test on push + check coverage
1 parent 7f6daba commit 9dd9271

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

.github/workflows/backend-test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: backend-test.yml
2+
3+
env:
4+
# raise that threshold over time
5+
COVERAGE_THRESHOLD: 2
6+
7+
on:
8+
push:
9+
paths:
10+
- 'backend/**'
11+
jobs:
12+
run-tests:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-go@v4
17+
with:
18+
go-version: '1.23'
19+
20+
- name: unit tests
21+
working-directory: ./backend
22+
run: |
23+
export TERM=xterm
24+
go test `go list ./... | grep -v "pkg/consapi\|pkg/api\|internal/th\|internal/contracts\|pkg/commons/types\|pkg/commons/contracts\|cmd"` -coverprofile coverage.out -covermode atomic -race
25+
26+
- name: coverage
27+
working-directory: ./backend
28+
run: |
29+
echo "Quality Gate: checking test coverage is above threshold ..."
30+
echo "Threshold : $COVERAGE_THRESHOLD %"
31+
totalCoverage=`go tool cover -func=coverage.out | grep ^total | grep -Eo '[0-9]+\.[0-9]+'`
32+
echo "Current test coverage : $totalCoverage %"
33+
if (( $(echo "$totalCoverage $COVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
34+
echo "OK"
35+
else
36+
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
37+
echo "Failed"
38+
exit 1
39+
fi

backend/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ local_deployment/.env
77
__gitignore
88
cmd/playground
99
pkg/api/docs/swagger.json
10+
coverage.out

backend/pkg/consapi/client_node_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func TestGetEvents(t *testing.T) {
202202

203203
for event := range res {
204204
if event.Error != nil {
205-
t.Errorf("Error getting event: %v", event.Error)
205+
t.Fatalf("Error getting event: %v", event.Error)
206206
}
207207

208208
if event.Event == types.EventHead {

0 commit comments

Comments
 (0)