Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    25
  • comments
    26
  • views
    26234

Running tests and getting coverage reports on server deployment in SnailLife

Sign in to follow this  
Liza Shulyayeva

558 views

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

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!