2017-07-05 17:15:59 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Run unit tests
|
|
|
|
#
|
|
|
|
# TESTFLAGS - add additional test flags. Ex:
|
|
|
|
#
|
|
|
|
# TESTFLAGS="-v -run TestBuild" hack/test/unit
|
|
|
|
#
|
|
|
|
# TESTDIRS - run tests for specified packages. Ex:
|
|
|
|
#
|
|
|
|
# TESTDIRS="./pkg/term" hack/test/unit
|
|
|
|
#
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
|
|
|
|
BUILDFLAGS=( -tags "netgo seccomp libdm_no_deferred_remove" )
|
|
|
|
TESTDIRS="${TESTDIRS:-"./..."}"
|
|
|
|
|
2017-07-12 19:13:37 -04:00
|
|
|
exclude_paths="/vendor/|/integration"
|
2017-07-05 17:15:59 -04:00
|
|
|
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
|
|
|
|
|
2017-09-19 18:00:54 -04:00
|
|
|
# install test dependencies once before running tests for each package. This
|
|
|
|
# significantly reduces the runtime.
|
|
|
|
go test -i "${BUILDFLAGS[@]}" $pkg_list
|
|
|
|
|
|
|
|
for pkg in $pkg_list; do
|
|
|
|
go test "${BUILDFLAGS[@]}" \
|
|
|
|
-cover \
|
|
|
|
-coverprofile=profile.out \
|
|
|
|
-covermode=atomic \
|
|
|
|
$TESTFLAGS \
|
|
|
|
"${pkg}"
|
|
|
|
|
|
|
|
if test -f profile.out; then
|
|
|
|
cat profile.out >> coverage.txt
|
|
|
|
rm profile.out
|
|
|
|
fi
|
|
|
|
done
|