File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,3 +38,8 @@ deps-upgrade:
3838# Removes all items from the Go module cache
3939deps-clean-cache :
4040 go clean -modcache
41+
42+ # Running code coverage
43+ # Generates code coverage report and logs the results
44+ coverage :
45+ sh ./sh/go_deps.sh
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # Set up directories and files
4+ LOG_DIR=" logs"
5+ COVERAGE_FILE=" $LOG_DIR /coverage.txt"
6+ PROFILE_FILE=" profile.out"
7+
8+ # Ensure the logs directory exists
9+ mkdir -p " $LOG_DIR "
10+
11+ # Exit immediately if a command exits with a non-zero status
12+ set -e
13+
14+ # Initialize the coverage file
15+ > " $COVERAGE_FILE "
16+
17+ # Run tests with race detection and coverage for each package
18+ for package in $( go list ./... | grep -v vendor) ; do
19+ go test -race -coverprofile=" $PROFILE_FILE " -covermode=atomic " $package "
20+
21+ # Append profile output to the coverage file if it exists
22+ if [ -f " $PROFILE_FILE " ]; then
23+ cat " $PROFILE_FILE " >> " $COVERAGE_FILE "
24+ rm " $PROFILE_FILE "
25+ fi
26+ done
27+
28+ echo " 🟢 Coverage results written to $COVERAGE_FILE "
You can’t perform that action at this time.
0 commit comments