Reading List
Running tests and getting coverage reports on server deployment in SnailLife from Liza Shulyayeva RSS feed.
Running tests and getting coverage reports on server deployment in SnailLife
Yesterday I added tests to server deployment in my deployServer.sh
script:
echo "Running tests"
cd ../../server/lib
set -e
echo "mode: set" > allcoverage.out
for d in $(go list ./... | grep -v vendor); do
parentdir=`dirname "$d"`
subdir=`basename "$d"`
echo "subdir: " $subdir
if [[ $subdir == "tests" ]]; then
go test -cover -coverpkg=$parentdir -coverprofile=profile.out $d
else
go test -cover -coverprofile=profile.out $d
fi
if [ -f profile.out ]; then
tail -n+2 profile.out >> allcoverage.out
rm profile.out
fi
done
Basically this goes into the root where all of my server packages live. Then for each found package we get the subdirectory name and the full path of the parent directory. If the subdirectory is named “tests” (most of my tests are in packages under the package I’m actually testing), we run go test -cover
with -coverpkg
specified as the parent dir of the test dir. Otherwise we do not specify -coverpkg
because it is in the same directory as the test.