1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

test: Add tools to generate test coverage information

This patch adds some tooling and scripts to generate test coverage
information.

Unfortunately, this involves some hacks as Go does not have support for
generating coverage-enabled binaries, or merging coverage reports; but
overall it's not very intrusive.
This commit is contained in:
Alberto Bertogli
2018-02-25 01:24:00 +00:00
parent 751fbd4b55
commit bb90274edd
11 changed files with 221 additions and 0 deletions

View File

@@ -29,6 +29,11 @@ function generate_cert() {
}
function chasquid() {
if [ "${COVER_DIR}" != "" ]; then
chasquid_cover "$@"
return
fi
# HOSTALIASES: so we "fake" hostnames.
# PATH: so chasquid can call test-mda without path issues.
# MDA_DIR: so our test-mda knows where to deliver emails.
@@ -38,6 +43,24 @@ function chasquid() {
go run ${RACE} ${TBASE}/../../chasquid.go "$@"
}
function chasquid_cover() {
# Build the coverage-enabled binary.
# See coverage_test.go for more details.
( cd ${TBASE}/../../;
go test -covermode=count -coverpkg=./... -c -tags coveragebin )
# Run the coverage-enabled binary, named "chasquid.test" for hacky
# reasons. See the chasquid function above for details on the
# environment variables.
HOSTALIASES=${TBASE}/hosts \
PATH=${UTILDIR}:${PATH} \
MDA_DIR=${TBASE}/.mail \
${TBASE}/../../chasquid.test \
-test.run "^TestRunMain$" \
-test.coverprofile="$COVER_DIR/test-`date +%s.%N`.out" \
"$@"
}
function add_user() {
CONFDIR="${CONFDIR:-config}"
DOMAIN=$(echo $1 | cut -d @ -f 2)