harbor/tests/coverage4gotest.sh
Wang Yan c6814f2bcc
move ci from travis to gitaction (#13891)
1, deprecate travis, and use the gitaction for instread.
2, upgrade golang version to v1.15.6

Signed-off-by: Wang Yan <wangyan@vmware.com>
2021-01-06 15:30:54 +08:00

38 lines
852 B
Bash
Executable File

#!/bin/bash
set -e
echo "mode: set" >>profile.cov
deps=""
# listDeps lists packages referenced by package in $1,
# excluding golang standard library and packages in
# direcotry vendor
function listDeps(){
pkg=$1
deps=$pkg
ds=$(echo $(go list -f '{{.Imports}}' $pkg) | sed 's/[][]//g')
for d in $ds
do
if echo $d | grep -q "github.com/goharbor/harbor" && echo $d | grep -qv "vendor"
then
deps="$deps,$d"
fi
done
}
packages=$(go list ./... | grep -v -E 'vendor|tests|testing')
for package in $packages
do
listDeps $package
# echo "DEBUG: testing package $package"
echo go test -race -v -cover -coverprofile=profile.tmp -coverpkg "$deps" $package
go test -race -v -cover -coverprofile=profile.tmp -coverpkg "$deps" $package
if [ -f profile.tmp ]
then
cat profile.tmp | tail -n +2 >> profile.cov
rm profile.tmp
fi
done