travis & README: add coveralls coverage report
authorStefan Junker <mail@stefanjunker.de>
Fri, 4 Mar 2016 19:19:26 +0000 (20:19 +0100)
committerStefan Junker <mail@stefanjunker.de>
Sat, 5 Mar 2016 18:07:31 +0000 (19:07 +0100)
Also, don't use sudo for the entire test script

.travis.yml
README.md
test

index 2c79690..1b2ebbe 100644 (file)
@@ -7,13 +7,18 @@ go:
   - 1.6
 
 env:
-  - TOOLS_CMD=golang.org/x/tools/cmd
+  global:
+    - TOOLS_CMD=golang.org/x/tools/cmd
+    - PATH=$GOROOT/bin:$PATH
 
 install:
  - go get ${TOOLS_CMD}/vet
+ - go get ${TOOLS_CMD}/cover
+ - go get github.com/modocache/gover
+ - go get github.com/mattn/goveralls
 
 script:
- - sudo -E /bin/bash -c 'PATH=$GOROOT/bin:$PATH ./test'
+ - ./test
 
 notifications:
   email: false
index a673252..2a00c07 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
 [![Build Status](https://travis-ci.org/appc/cni.svg?branch=master)](https://travis-ci.org/appc/cni)
+[![Coverage Status](https://coveralls.io/repos/github/appc/cni/badge.svg?branch=master)](https://coveralls.io/github/appc/cni?branch=master)
 
 # cni - the Container Network Interface
 
diff --git a/test b/test
index faccf1c..3811771 100755 (executable)
--- a/test
+++ b/test
@@ -33,8 +33,23 @@ fi
 split=(${TEST// / })
 TEST=${split[@]/#/${REPO_PATH}/}
 
-echo "Running tests..."
-go test ${COVER} $@ ${TEST}
+echo -n "Running tests "
+function testrun {
+    sudo -E bash -c "umask 0; PATH=\$GOROOT/bin:\$PATH go test -covermode set $@"
+}
+if [ ! -z "${COVERALLS}" ]; then
+    echo "with coverage profile generation..."
+    i=0
+    for t in ${TEST}; do 
+        testrun "-coverprofile ${i}.coverprofile ${t}"
+        i=$((i+1))
+    done 
+    gover
+    goveralls -service=travis-ci -coverprofile=gover.coverprofile -repotoken=$COVERALLS_TOKEN
+else 
+    echo "without coverage profile generation..."
+    testrun "${TEST}"
+fi
 
 echo "Checking gofmt..."
 fmtRes=$(gofmt -l $FMT)