harbor/tests/coverage4gotest.sh
Daniel Jiang 3f7c605cf5
[WIP] Remove vendor folder from harbor code base (#19508)
* Remove vendor folder from harbor code base

Signed-off-by: Daniel Jiang <jiangd@vmware.com>

* debug ut failure

* debug failure

* debug failure

---------

Signed-off-by: Daniel Jiang <jiangd@vmware.com>
2023-11-05 14:37:25 +08:00

40 lines
872 B
Bash
Executable File

#!/bin/bash
set -x
set -e
echo "mode: set" >>profile.cov
deps=""
cd $(dirname $(find . -name go.mod))
set +x
# listDeps lists packages referenced by package in $1,
# excluding golang standard library
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
then
deps="$deps,$d"
fi
done
}
packages=$(go list ./... | grep -v -E 'tests|testing')
echo testing packages: $packages
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