From 2c797384ff520358649ffd7bd538af7f91147cb9 Mon Sep 17 00:00:00 2001
From: Dave Tucker
Date: Tue, 14 Apr 2015 13:13:34 +0100
Subject: [PATCH] Report Code Coverage and Add Status Badges
- Update Makefile to generate coverage details when running the tests
- Update CircleCI to use the Makefile
- Add Build and Coverage Badges to README
Closes #20
Signed-off-by: Dave Tucker
---
libnetwork/.gitignore | 4 ++++
libnetwork/Makefile | 32 ++++++++++++++++++++++++++++----
libnetwork/README.md | 3 +++
libnetwork/circle.yml | 23 ++++-------------------
4 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/libnetwork/.gitignore b/libnetwork/.gitignore
index daf913b1b3..ce7eb7209d 100644
--- a/libnetwork/.gitignore
+++ b/libnetwork/.gitignore
@@ -22,3 +22,7 @@ _testmain.go
*.exe
*.test
*.prof
+
+# Coverage
+*.tmp
+*.coverprofile
diff --git a/libnetwork/Makefile b/libnetwork/Makefile
index e8d270b92e..c3428f7d80 100644
--- a/libnetwork/Makefile
+++ b/libnetwork/Makefile
@@ -1,6 +1,9 @@
-.PHONY: all all-local build build-local check check-code check-format run-tests check-local install-deps
+.PHONY: all all-local build build-local check check-code check-format run-tests check-local install-deps coveralls circle-ci
-docker = docker run --rm --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork golang:1.4
+dockerargs = --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork golang:1.4
+docker = docker run --rm ${dockerargs}
+ciargs = -e "COVERALLS_TOKEN=$$COVERALLS_TOKEN"
+cidocker = docker run ${ciargs} ${dockerargs}
all:
${docker} make all-local
@@ -21,10 +24,19 @@ check-code:
go vet ./...
check-format:
- test -z "$$(shell goimports -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
+ test -z "$$(goimports -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
run-tests:
- $(shell which godep) go test -test.v ./...
+ echo "mode: count" > coverage.coverprofile
+ for dir in $$(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d); do \
+ if ls $$dir/*.go &> /dev/null; then \
+ $(shell which godep) go test -test.v -covermode=count -coverprofile=$$dir/profile.tmp $$dir ; \
+ if [ -f $$dir/profile.tmp ]; then \
+ cat $$dir/profile.tmp | tail -n +2 >> coverage.coverprofile ; \
+ rm $$dir/profile.tmp ; \
+ fi ; \
+ fi ; \
+ done
check-local: check-format check-code run-tests
@@ -34,3 +46,15 @@ install-deps:
go get github.com/golang/lint/golint
go get golang.org/x/tools/cmd/vet
go get golang.org/x/tools/cmd/goimports
+ go get golang.org/x/tools/cmd/cover
+ go get github.com/mattn/goveralls
+
+coveralls:
+ @goveralls -service circleci -coverprofile=coverage.coverprofile -repotoken $$COVERALLS_TOKEN
+
+# CircleCI's Docker fails when cleaning up using the --rm flag
+# The following target is a workaround for this
+
+circle-ci:
+ @${cidocker} make install-deps check-local coveralls
+
diff --git a/libnetwork/README.md b/libnetwork/README.md
index 5fee2a195e..46b326b721 100644
--- a/libnetwork/README.md
+++ b/libnetwork/README.md
@@ -1,4 +1,7 @@
# libnetwork - networking for containers
+
+[![Circle CI](https://circleci.com/gh/docker/libnetwork/tree/master.svg?style=svg)](https://circleci.com/gh/docker/libnetwork/tree/master) [![Coverage Status](https://coveralls.io/repos/docker/libnetwork/badge.svg)](https://coveralls.io/r/docker/libnetwork)
+
Libnetwork provides a native Go implementation for connecting containers
The goal of libnetwork is to deliver a robust Container Network Model that provides a consistent programming interface and the required network abstractions for applications.
diff --git a/libnetwork/circle.yml b/libnetwork/circle.yml
index 1b53f2445f..d02f6a92ed 100644
--- a/libnetwork/circle.yml
+++ b/libnetwork/circle.yml
@@ -1,27 +1,12 @@
machine:
- environment:
- BASE_DIR: src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME
- CHECKOUT: /home/ubuntu/$CIRCLE_PROJECT_REPONAME
- pre:
- # sudo -E doesn't preserve $PATH, so go isn't found anymore.
- - sudo ln -s $(which go) /usr/local/bin
-
-checkout:
- post:
- # We need docker/libnetwork itself in the GOPATH for imports to work.
- - ln -s $CHECKOUT $(echo $GOPATH | cut -d":" -f1)/$BASE_DIR
+ services:
+ - docker
dependencies:
override:
- - go get github.com/tools/godep
- post:
- - go get github.com/golang/lint/golint
- - go get golang.org/x/tools/cmd/goimports
+ - echo "Nothing to install"
test:
override:
- - test -z "$(goimports -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
- - go vet ./...
- - test -z "$(golint ./... | tee /dev/stderr)"
- - sudo -E $(which godep) go test -test.v ./...
+ - make circle-ci