Files
weave-scope/test
Tom Wilkie a7eef92988 Squashed 'tools/' changes from 1fc4d66..3ec519f
3ec519f Merge pull request #12 from weaveworks/prefix-unit-test-sched
856790f Use golang package name as a prefix on unit test schedules.
7f5fa57 Merge pull request #11 from weaveworks/10-dont-delete-sshed-gce-nodes
0bff9b4 Don't delete GCE nodes for running (but failed) builds
03aed8f Merge pull request #9 from weaveworks/configure-pac-domain
c04c534 socks: Make main shExpMatch expression configurable

git-subtree-dir: tools
git-subtree-split: 3ec519f704
2015-12-07 14:53:05 +00:00

93 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GO_TEST_ARGS="-tags netgo -cpu 4 -timeout 8m"
SLOW=
NO_GO_GET=
usage() {
echo "$0 [-slow] [-in-container foo]"
}
while [ $# -gt 0 ]; do
case "$1" in
"-slow")
SLOW=true
shift 1
;;
"-no-go-get")
NO_GO_GET=true
shift 1
;;
*)
usage
exit 2
;;
esac
done
if [ -n "$SLOW" -o -n "$CIRCLECI" ]; then
SLOW=true
fi
if [ -n "$SLOW" ]; then
GO_TEST_ARGS="$GO_TEST_ARGS -race -covermode=atomic"
if [ -n "$COVERDIR" ] ; then
coverdir="$COVERDIR"
else
coverdir=$(mktemp -d coverage.XXXXXXXXXX)
fi
mkdir -p $coverdir
fi
fail=0
TESTDIRS=$(find . -type f -name '*_test.go' | xargs -n1 dirname | grep -vE '^\./(\.git|vendor|prog|experimental)/' | sort -u)
# If running on circle, use the scheduler to work out what tests to run on what shard
if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" -a -x "$DIR/sched" ]; then
PREFIX=$(go list -e ./ | sed -e 's/\//-/g')
TESTDIRS=$(echo $TESTDIRS | "$DIR/sched" sched $PREFIX-$CIRCLE_BUILD_NUM $CIRCLE_NODE_TOTAL $CIRCLE_NODE_INDEX)
echo $TESTDIRS
fi
PACKAGE_BASE=$(go list -e ./)
for dir in $TESTDIRS; do
if [ -z "$NO_GO_GET" ]; then
go get -t -tags netgo $dir
fi
GO_TEST_ARGS_RUN="$GO_TEST_ARGS"
if [ -n "$SLOW" ]; then
COVERPKGS=$( (go list $dir; go list -f '{{join .Deps "\n"}}' $dir | grep -v "vendor" | grep "^$PACKAGE_BASE/") | paste -s -d, -)
output=$(mktemp $coverdir/unit.XXXXXXXXXX)
GO_TEST_ARGS_RUN="$GO_TEST_ARGS -coverprofile=$output -coverpkg=$COVERPKGS"
fi
START=$(date +%s)
if ! go test $GO_TEST_ARGS_RUN $dir; then
fail=1
fi
RUNTIME=$(( $(date +%s) - $START ))
# Report test runtime when running on circle, to help scheduler
if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" -a -x "$DIR/sched" ]; then
"$DIR/sched" time $dir $RUNTIME
fi
done
if [ -n "$SLOW" -a -z "$COVERDIR" ] ; then
go get github.com/weaveworks/tools/cover
cover $coverdir/* >profile.cov
rm -rf $coverdir
go tool cover -html=profile.cov -o=coverage.html
go tool cover -func=profile.cov | tail -n1
fi
exit $fail