diff --git a/.travis.yml b/.travis.yml index 3e39eef0..3242a3db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile b/Makefile index 79a465ef..6adf7dea 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/build/build.sh b/build/build.sh index 7c6d13a4..25d3515b 100644 --- a/build/build.sh +++ b/build/build.sh @@ -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%/*} diff --git a/circle.yml b/circle.yml index 5ac5cc3d..0d1298f8 100644 --- a/circle.yml +++ b/circle.yml @@ -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 diff --git a/test/units.sh b/test/units.sh new file mode 100755 index 00000000..2a383c7a --- /dev/null +++ b/test/units.sh @@ -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