Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend ci): run unit test on push + check coverage #1304

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/backend-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: backend-test.yml

env:
# raise that threshold over time
COVERAGE_THRESHOLD: 2

on:
push:
paths:
- 'backend/**'
jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: unit tests
working-directory: ./backend
run: |
export TERM=xterm
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

- name: coverage
working-directory: ./backend
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $COVERAGE_THRESHOLD %"
totalCoverage=`go tool cover -func=coverage.out | grep ^total | grep -Eo '[0-9]+\.[0-9]+'`
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $COVERAGE_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
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ local_deployment/.env
__gitignore
cmd/playground
pkg/api/docs/swagger.json
coverage.out
2 changes: 1 addition & 1 deletion backend/pkg/consapi/client_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func TestGetEvents(t *testing.T) {

for event := range res {
if event.Error != nil {
t.Errorf("Error getting event: %v", event.Error)
t.Fatalf("Error getting event: %v", event.Error)
}

if event.Event == types.EventHead {
Expand Down
Loading