Merge pull request #1115 from weaveworks/unit-coverage

Run unit tests in circle and include their coverage in the report.
This commit is contained in:
Tom Wilkie committed 2015-07-10 19:34:48 +01:00
commit 56a169b50f
5 files changed
+40 -19

No files matched your search

-1
View File
@@ -26,5 +26,4 @@ script:
after_success:
- go get github.com/mattn/goveralls
- $HOME/gopath/bin/goveralls -coverprofile=profile.cov -service=travis-ci
- test "${TRAVIS_PULL_REQUEST}" = "false" && site/build-and-publish.sh
+2 -16
View File
@@ -107,22 +107,7 @@ $(DOCKER_DISTRIB):
curl -o $(DOCKER_DISTRIB) $(DOCKER_DISTRIB_URL)
tests:
echo "mode: count" > profile.cov
fail=0 ; \
for dir in $$(find . -type f -name '*_test.go' | xargs -n1 dirname | grep -v prog | sort -u); do \
go get -t -tags netgo $$dir ; \
output=$$(mktemp cover.XXXXXXXXXX) ; \
if ! go test -cpu 4 -tags netgo \
-covermode=count -coverprofile=$$output $$dir ; then \
fail=1 ; \
fi ; \
if [ -f $$output ]; then \
tail -n +2 <$$output >>profile.cov; \
rm $$output; \
fi \
done ; \
exit $$fail
go tool cover -html=profile.cov -o=coverage.html
@test/units.sh
$(PUBLISH): publish_%:
$(SUDO) docker tag -f $(DOCKERHUB_USER)/$* $(DOCKERHUB_USER)/$*:$(WEAVE_VERSION)
@@ -133,6 +118,7 @@ publish: $(PUBLISH)
clean:
-$(SUDO) docker rmi $(IMAGES)
go clean -r ./...
rm -f $(EXES) $(IMAGES_UPTODATE) $(WEAVE_EXPORT)
rm -f test/tls/*.pem
+7 -2
View File
@@ -6,7 +6,7 @@ export GOPATH
WEAVE_SRC=$GOPATH/src/github.com/weaveworks/weave
if [ $# -eq 0 ] ; then
if [ $# -eq 0 -o "$1" = "tests" ] ; then
# No arguments. Expect that the weave repo will be bind-mounted
# into $GOPATH
if ! [ -e $WEAVE_SRC ] ; then
@@ -35,7 +35,12 @@ EOF
echo "weave:x:$uid:$gid::$WEAVE_SRC:/bin/sh" >>/etc/passwd
echo "weave:*:::::::" >>/etc/shadow
echo "weave ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
su weave -c "PATH=$PATH make -C $WEAVE_SRC build"
if [ "$1" = "tests" ] ; then
su weave -c "PATH=$PATH make -C $WEAVE_SRC tests"
else
su weave -c "PATH=$PATH make -C $WEAVE_SRC build"
fi
else
# There are arguments to pass to git-clone
mkdir -p ${WEAVE_SRC%/*}
+3
View File
@@ -35,6 +35,8 @@ dependencies:
test:
override:
- test "$CIRCLE_NODE_INDEX" != "0" || (docker run -v /var/run/docker.sock:/run/docker.sock -v /home/ubuntu:/home/go -e "COVERDIR=test/coverage" weaveworks/weave-build tests):
parallel: true
- docker run -v /var/run/docker.sock:/run/docker.sock -v /home/ubuntu:/home/go -e COVERAGE=true weaveworks/weave-build:
parallel: true
- cd $SRCDIR/test; ./gce.sh setup:
@@ -52,5 +54,6 @@ teardown:
pre:
- test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; ./gen_coverage_reports.sh):
parallel: true
- test "$CIRCLE_NODE_INDEX" != "0" || (go get github.com/mattn/goveralls && goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=$SRCDIR/test/profile.cov -service=circleci || true)
- test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; cp coverage.* $CIRCLE_ARTIFACTS):
parallel: true
Executable
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
go get github.com/weaveworks/weave/testing/cover
if [ -n "$COVERDIR" ] ; then
coverdir="$COVERDIR"
else
coverdir=$(mktemp -d coverage.XXXXXXXXXX)
fi
mkdir -p $coverdir
fail=0
for dir in $(find . -type f -name '*_test.go' | xargs -n1 dirname | grep -v prog | sort -u); do
go get -t -tags netgo $dir
output=$(mktemp $coverdir/unit.XXXXXXXXXX)
if ! go test -cpu 4 -tags netgo -covermode=count -coverprofile=$output $dir ; then
fail=1
fi
done
if [ -z "$COVERDIR" ] ; then
cover $coverdir/* >profile.cov
rm -rf $coverdir
go tool cover -html=profile.cov -o=coverage.html
fi
exit $fail