mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
Merge pull request #1491 from prymitive/test-script
fix(tests): report total go coverage while running tests
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"mime"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -89,6 +90,8 @@ func headerAuth(name, valueRegex string) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
func setupRouter(router *gin.Engine) {
|
||||
_ = mime.AddExtensionType(".ico", "image/x-icon")
|
||||
|
||||
router.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||
|
||||
router.Use(setStaticHeaders(getViewURL("/static/")))
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
trap cleanup INT
|
||||
|
||||
function cleanup() {
|
||||
rm -f coverage.txt coverage.out profile.out
|
||||
exit
|
||||
}
|
||||
|
||||
echo "" > coverage.txt
|
||||
|
||||
for d in $(go list ./... | grep -vE 'prymitive/karma/internal/mapper/v017/(client|models)'); do
|
||||
go test \
|
||||
-coverprofile=profile.out \
|
||||
-coverpkg=$(go list ./... | grep -vE 'prymitive/karma/internal/mapper/v017/(client|models)' | tr '\n' ',') \
|
||||
$d 2>&1 | grep -v 'warning: no packages being tested depend on matches for pattern' | sed s/'of statements in .*'/''/g
|
||||
PKGS=$(go list ./... | grep -vE 'prymitive/karma/internal/mapper/v017/(client|models)')
|
||||
COVERPKG=$(echo "$PKGS" | tr '\n' ',')
|
||||
for d in $PKGS; do
|
||||
(go test -coverprofile=profile.out -coverpkg="$COVERPKG" $d 2>&1 || exit 2) \
|
||||
| grep -v 'warning: no packages being tested depend on matches for pattern' \
|
||||
| sed s/'of statements in .*'/''/g
|
||||
if [ -f profile.out ]; then
|
||||
cat profile.out >> coverage.txt
|
||||
rm profile.out
|
||||
fi
|
||||
done
|
||||
|
||||
echo "mode: set" > coverage.out
|
||||
cat coverage.txt | grep -v "mode: set" | grep -vE '^$' | grep -vE '^github.com/prymitive/karma/cmd/karma/bindata_assetfs.go:' >> coverage.out
|
||||
mv coverage.out coverage.txt
|
||||
go tool cover -func coverage.txt | tail -n 1 | awk '{print $3}'
|
||||
|
||||
Reference in New Issue
Block a user