Add coverage to proxy for integration tests.

This commit is contained in:
Tom Wilkie committed 2015-07-29 12:06:29 +00:00
1 parent 77358140d9
commit 6fe69590c4
6 files changed
+28 -12

No files matched your search

+3 -3
View File
@@ -33,7 +33,6 @@ WEAVE_EXPORT=weave.tar
WEAVEEXEC_DOCKER_VERSION=1.3.1
DOCKER_DISTRIB=prog/weaveexec/docker-$(WEAVEEXEC_DOCKER_VERSION).tgz
DOCKER_DISTRIB_URL=https://get.docker.com/builds/Linux/x86_64/docker-$(WEAVEEXEC_DOCKER_VERSION).tgz
COVERAGE_MODULES=$(shell go list -f '{{join .Deps "\n"}}' ./prog/weaver | grep "weaveworks" | paste -s -d,)
NETGO_CHECK=@strings $@ | grep cgo_stub\\\.go >/dev/null || { \
rm $@; \
echo "\nYour go standard library was built without the 'netgo' build tag."; \
@@ -50,8 +49,9 @@ travis: $(EXES)
update:
go get -u -f -v -tags -netgo $(addprefix ./,$(dir $(EXES)))
$(WEAVER_EXE): common/*.go common/*/*.go net/*.go
$(WEAVER_EXE) $(WEAVEPROXY_EXE): common/*.go common/*/*.go net/*.go
ifeq ($(COVERAGE),true)
$(eval COVERAGE_MODULES := $(shell (go list ./$(@D); go list -f '{{join .Deps "\n"}}' ./$(@D) | grep "weaveworks") | paste -s -d,))
go get -t -tags netgo ./$(@D)
go test -c -o ./$@ -ldflags "-extldflags \"-static\" -X main.version $(WEAVE_VERSION)" \
-tags netgo -v -covermode=atomic -coverpkg $(COVERAGE_MODULES) ./$(@D)/
@@ -61,7 +61,7 @@ else
endif
$(NETGO_CHECK)
$(WEAVEPROXY_EXE) $(NETCHECK_EXE): common/*.go common/*/*.go net/*.go
$(NETCHECK_EXE): common/*.go common/*/*.go net/*.go
go get -tags netgo ./$(@D)
go build -ldflags "-extldflags \"-static\" -X main.version $(WEAVE_VERSION)" -tags netgo -o $@ ./$(@D)
$(NETGO_CHECK)
+2 -1
View File
@@ -82,5 +82,6 @@ func main() {
Log.Fatalf("Could not start proxy: %s", err)
}
p.ListenAndServe()
go p.ListenAndServe()
SignalHandlerLoop()
}
+12
View File
@@ -0,0 +1,12 @@
package main
import (
"testing"
weavetest "github.com/weaveworks/weave/testing"
)
func TestMain(t *testing.T) {
weavetest.TrimTestArgs()
main()
}
+1 -1
View File
@@ -5,7 +5,7 @@
start_suite "Boot the proxy should only listen on client's interface"
# Booting it over unix socket listens on unix socket
run_on $HOST1 sudo weave launch-proxy
run_on $HOST1 COVERAGE=$COVERAGE sudo -E weave launch-proxy
assert_raises "run_on $HOST1 sudo docker -H unix:///var/run/weave.sock ps"
assert_raises "proxy docker_on $HOST1 ps" 1
weave_on $HOST1 stop-proxy
+7 -4
View File
@@ -117,8 +117,10 @@ stop_router_on() {
# the weave container, which means we a) can't grab coverage
# stats, and b) can't inspect the logs when tests fail.
docker_on $host stop weave 1>/dev/null 2>&1 || true
docker_on $host stop weaveproxy 1>/dev/null 2>&1 || true
if [ -n "$COVERAGE" ] ; then
collect_coverage $host
collect_coverage $host weave
collect_coverage $host weaveproxy
fi
}
@@ -207,11 +209,12 @@ end_suite() {
collect_coverage() {
host=$1
container=$2
mkdir -p ./coverage
rm -f cover.router.prof
docker_on $host cp weave:/home/weave/cover.router.prof . 2>/dev/null || return 0
rm -f cover.prof
docker_on $host cp $container:/home/weave/cover.prof . 2>/dev/null || return 0
# ideally we'd know the name of the test here, and put that in the filename
mv cover.router.prof $(mktemp -u ./coverage/integration.XXXXXXXX) || true
mv cover.prof $(mktemp -u ./coverage/integration.XXXXXXXX) || true
}
WEAVE=$DIR/../weave
+3 -3
View File
@@ -199,7 +199,7 @@ PROXY_PORT=12375
PROXY_CONTAINER_NAME=weaveproxy
COVERAGE_ARGS=""
if [ -n "$COVERAGE" ] ; then
COVERAGE_ARGS="-test.coverprofile=/home/weave/cover.router.prof --"
COVERAGE_ARGS="-test.coverprofile=/home/weave/cover.prof --"
fi
######################################################################
@@ -433,7 +433,7 @@ ask_version() {
fi
fi
VERSION_COVERAGE_ARGS=""
if [ "$1" = "$CONTAINER_NAME" ] ; then
if [ "$1" = "$CONTAINER_NAME" ] || [ "$1" == "$PROXY_CONTAINER_NAME"] ; then
VERSION_COVERAGE_ARGS="$COVERAGE_ARGS"
fi
[ -n "$DOCKERIMAGE" ] && docker run --rm -e WEAVE_CIDR=none $DOCKERIMAGE $VERSION_COVERAGE_ARGS --version
@@ -1137,7 +1137,7 @@ launch_proxy() {
-e WEAVE_CIDR=none \
-e DOCKER_BRIDGE \
--entrypoint=/home/weave/weaveproxy \
$WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $PROXY_ARGS)
$WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $COVERAGE_ARGS $PROXY_ARGS)
wait_for_log $PROXY_CONTAINER_NAME "proxy listening"
}