Reading List
The most recent articles from a list of feeds I subscribe to.
Testing SnailLife Go repositories
Every SnailLife model struct has a repository struct to go with it. Since all repos are implementing the same Repository interface I wanted to reuse most of the code for testing them, but also allow for custom repo-specific tests. For example,OwnerRepo
does some stuff that StableRepo
does not - like optionally retrieving stables belonging to an owner.
Excluding mocks from coverage reports
I noticed that my coverage reports were including mock packages.
To get rid of this instead of running go test
like this:
Testing SnailLife Go on Go 1.10
This is quick braindump of getting SnailLife Go building and testing on Go 1.10.
A few days ago I decided to start building and testing SnailLife Go on Go 1.10 RC 1 (now RC 2). It took a bit of wrangling, but after updating my local environment and finding the best image to use for GitLab CI, I now have it building on Go 1.9 and 1.10 rc 2.
GitLab CI for SnailLife Go
I finally got GitLab CI up and running for the SnailLife Go port. The CI just runs the bash scripts I already had to test and build client and server. I had to make some changes for the tests to be able to run without the auth config files (which I obviously don’t want to submit to a public repo). Now, if an auth config file is not available I look for environment variables to get the Auth0 client ID and secret. Gitlab lets you set secret environment variables for the CI to use. I did something similar to get the name of the environment - if an env file with the environment name is not found, we check environment variables for the name (and then load relevant configs from there).
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.