2021-04-24 15:10:24 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-10-01 20:28:33 +08:00
|
|
|
FILE_COVERAGE_INFO="go_coverage.txt"
|
|
|
|
FILE_COVERAGE_HTML="go_coverage.html"
|
|
|
|
|
2021-04-24 15:10:24 +08:00
|
|
|
set -e
|
2021-10-01 20:28:33 +08:00
|
|
|
echo "mode: atomic" > ${FILE_COVERAGE_INFO}
|
2021-04-24 15:10:24 +08:00
|
|
|
|
2021-10-03 17:48:10 +08:00
|
|
|
# run unittest
|
2021-10-06 19:26:54 +08:00
|
|
|
echo "Running unittest under ./internal"
|
2021-04-24 15:10:24 +08:00
|
|
|
for d in $(go list ./internal... | grep -v vendor); do
|
2021-08-23 22:01:51 +08:00
|
|
|
go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic "$d"
|
2021-04-24 15:10:24 +08:00
|
|
|
if [ -f profile.out ]; then
|
2021-10-01 20:28:33 +08:00
|
|
|
sed '1d' profile.out >> ${FILE_COVERAGE_INFO}
|
2021-04-24 15:10:24 +08:00
|
|
|
rm profile.out
|
|
|
|
fi
|
|
|
|
done
|
2021-09-22 16:01:53 +08:00
|
|
|
|
2021-10-03 17:48:10 +08:00
|
|
|
# generate html report
|
2021-10-01 20:28:33 +08:00
|
|
|
go tool cover -html=./${FILE_COVERAGE_INFO} -o ./${FILE_COVERAGE_HTML}
|
2021-10-04 09:03:55 +08:00
|
|
|
echo "Generate go coverage report to ${FILE_COVERAGE_HTML}"
|