| ... | ... |
@@ -65,6 +65,9 @@ RUN git clone https://git.fedorahosted.org/git/lvm2.git /usr/local/lvm2 && cd /u |
| 65 | 65 |
RUN cd /usr/local/lvm2 && ./configure --enable-static_link && make device-mapper && make install_device-mapper |
| 66 | 66 |
# see https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL |
| 67 | 67 |
|
| 68 |
+# Grab Go's cover tool for dead-simple code coverage testing |
|
| 69 |
+RUN go get code.google.com/p/go.tools/cmd/cover |
|
| 70 |
+ |
|
| 68 | 71 |
VOLUME /var/lib/docker |
| 69 | 72 |
WORKDIR /go/src/github.com/dotcloud/docker |
| 70 | 73 |
|
| ... | ... |
@@ -39,6 +39,7 @@ DEFAULT_BUNDLES=( |
| 39 | 39 |
dynbinary |
| 40 | 40 |
dyntest |
| 41 | 41 |
dyntest-integration |
| 42 |
+ cover |
|
| 42 | 43 |
tgz |
| 43 | 44 |
ubuntu |
| 44 | 45 |
) |
| ... | ... |
@@ -64,6 +65,11 @@ LDFLAGS='-X main.GITCOMMIT "'$GITCOMMIT'" -X main.VERSION "'$VERSION'" -w' |
| 64 | 64 |
LDFLAGS_STATIC='-X github.com/dotcloud/docker/utils.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"' |
| 65 | 65 |
BUILDFLAGS='-tags netgo' |
| 66 | 66 |
|
| 67 |
+HAVE_GO_TEST_COVER= |
|
| 68 |
+if go help testflag | grep -q -- -cover; then |
|
| 69 |
+ HAVE_GO_TEST_COVER=1 |
|
| 70 |
+fi |
|
| 71 |
+ |
|
| 67 | 72 |
# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. |
| 68 | 73 |
# You can use this to select certain tests to run, eg. |
| 69 | 74 |
# |
| ... | ... |
@@ -71,6 +77,14 @@ BUILDFLAGS='-tags netgo' |
| 71 | 71 |
# |
| 72 | 72 |
go_test_dir() {
|
| 73 | 73 |
dir=$1 |
| 74 |
+ testcover=() |
|
| 75 |
+ if [ "$HAVE_GO_TEST_COVER" ]; then |
|
| 76 |
+ # if our current go install has -cover, we want to use it :) |
|
| 77 |
+ mkdir -p "$DEST/coverprofiles" |
|
| 78 |
+ coverprofile="docker${dir#.}"
|
|
| 79 |
+ coverprofile="$DEST/coverprofiles/${coverprofile//\//-}"
|
|
| 80 |
+ testcover=( -cover -coverprofile "$coverprofile" ) |
|
| 81 |
+ fi |
|
| 74 | 82 |
( # we run "go test -i" ouside the "set -x" to provde cleaner output |
| 75 | 83 |
cd "$dir" |
| 76 | 84 |
go test -i -ldflags "$LDFLAGS" $BUILDFLAGS |
| ... | ... |
@@ -78,7 +92,7 @@ go_test_dir() {
|
| 78 | 78 |
( |
| 79 | 79 |
set -x |
| 80 | 80 |
cd "$dir" |
| 81 |
- go test -ldflags "$LDFLAGS" $BUILDFLAGS $TESTFLAGS |
|
| 81 |
+ go test ${testcover[@]} -ldflags "$LDFLAGS" $BUILDFLAGS $TESTFLAGS
|
|
| 82 | 82 |
) |
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 | 85 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,21 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+ |
|
| 2 |
+DEST="$1" |
|
| 3 |
+ |
|
| 4 |
+bundle_cover() {
|
|
| 5 |
+ coverprofiles=( "$DEST/../"*"/coverprofiles/"* ) |
|
| 6 |
+ for p in "${coverprofiles[@]}"; do
|
|
| 7 |
+ echo |
|
| 8 |
+ ( |
|
| 9 |
+ set -x |
|
| 10 |
+ go tool cover -func="$p" |
|
| 11 |
+ ) |
|
| 12 |
+ done |
|
| 13 |
+} |
|
| 14 |
+ |
|
| 15 |
+if [ "$HAVE_GO_TEST_COVER" ]; then |
|
| 16 |
+ bundle_cover 2>&1 | tee "$DEST/report.log" |
|
| 17 |
+else |
|
| 18 |
+ echo >&2 'warning: the current version of go does not support -cover' |
|
| 19 |
+ echo >&2 ' skipping test coverage report' |
|
| 20 |
+fi |