Running tests and getting coverage reports on server deployment in SnailLife

posted in SnailLife
Published October 24, 2017
Advertisement

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. 

At the end we get an allcoverage.out file which can be opened in the browser to view coverage for each tested source file:

coverage.thumb.png.e98e148e43b1796c4c3a99c56cd39257.png

1 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement