If coverpkg is missing on `go test` command, only the current package
will be covered. That's the case of unit tests. For integration tests
we need to explicitly declare each package.
Docker-DCO-1.1-Signed-off-by: Fabio Falci <fabiofalci@gmail.com> (github: fabiofalci)
| ... | ... |
@@ -16,7 +16,7 @@ set -e |
| 16 | 16 |
# in the Dockerfile at the root of the source. In other words: |
| 17 | 17 |
# DO NOT CALL THIS SCRIPT DIRECTLY. |
| 18 | 18 |
# - The right way to call this script is to invoke "make" from |
| 19 |
-# your checkout of the Docker repository. |
|
| 19 |
+# your checkout of the Docker repository. |
|
| 20 | 20 |
# the Makefile will do a "docker build -t docker ." and then |
| 21 | 21 |
# "docker run hack/make.sh" in the resulting container image. |
| 22 | 22 |
# |
| ... | ... |
@@ -101,13 +101,14 @@ fi |
| 101 | 101 |
# |
| 102 | 102 |
go_test_dir() {
|
| 103 | 103 |
dir=$1 |
| 104 |
+ coverpkg=$2 |
|
| 104 | 105 |
testcover=() |
| 105 | 106 |
if [ "$HAVE_GO_TEST_COVER" ]; then |
| 106 | 107 |
# if our current go install has -cover, we want to use it :) |
| 107 | 108 |
mkdir -p "$DEST/coverprofiles" |
| 108 | 109 |
coverprofile="docker${dir#.}"
|
| 109 | 110 |
coverprofile="$DEST/coverprofiles/${coverprofile//\//-}"
|
| 110 |
- testcover=( -cover -coverprofile "$coverprofile" ) |
|
| 111 |
+ testcover=( -cover -coverprofile "$coverprofile" $coverpkg ) |
|
| 111 | 112 |
fi |
| 112 | 113 |
( |
| 113 | 114 |
set -x |
| ... | ... |
@@ -116,6 +117,16 @@ go_test_dir() {
|
| 116 | 116 |
) |
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 |
+# This helper function walks the current directory looking for directories |
|
| 120 |
+# holding certain files ($1 parameter), and prints their paths on standard |
|
| 121 |
+# output, one per line. |
|
| 122 |
+find_dirs() {
|
|
| 123 |
+ find -not \( \ |
|
| 124 |
+ \( -wholename './vendor' -o -wholename './integration' -o -wholename './contrib' -o -wholename './pkg/mflag/example' \) \ |
|
| 125 |
+ -prune \ |
|
| 126 |
+ \) -name "$1" -print0 | xargs -0n1 dirname | sort -u |
|
| 127 |
+} |
|
| 128 |
+ |
|
| 119 | 129 |
bundle() {
|
| 120 | 130 |
bundlescript=$1 |
| 121 | 131 |
bundle=$(basename $bundlescript) |
| ... | ... |
@@ -19,7 +19,7 @@ bundle_test() {
|
| 19 | 19 |
date |
| 20 | 20 |
|
| 21 | 21 |
TESTS_FAILED=() |
| 22 |
- for test_dir in $(find_test_dirs); do |
|
| 22 |
+ for test_dir in $(find_dirs '*_test.go'); do |
|
| 23 | 23 |
echo |
| 24 | 24 |
|
| 25 | 25 |
if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir "$test_dir"; then |
| ... | ... |
@@ -48,15 +48,4 @@ bundle_test() {
|
| 48 | 48 |
} 2>&1 | tee $DEST/test.log |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 |
- |
|
| 52 |
-# This helper function walks the current directory looking for directories |
|
| 53 |
-# holding Go test files, and prints their paths on standard output, one per |
|
| 54 |
-# line. |
|
| 55 |
-find_test_dirs() {
|
|
| 56 |
- find -not \( \ |
|
| 57 |
- \( -wholename './vendor' -o -wholename './integration' \) \ |
|
| 58 |
- -prune \ |
|
| 59 |
- \) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u |
|
| 60 |
-} |
|
| 61 |
- |
|
| 62 | 51 |
bundle_test |
| ... | ... |
@@ -5,7 +5,8 @@ DEST=$1 |
| 5 | 5 |
set -e |
| 6 | 6 |
|
| 7 | 7 |
bundle_test_integration() {
|
| 8 |
- LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir ./integration |
|
| 8 |
+ LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir ./integration \ |
|
| 9 |
+ "-coverpkg $(find_dirs '*.go' | sed 's,^\.,github.com/dotcloud/docker,g' | paste -d, -s)" |
|
| 9 | 10 |
} |
| 10 | 11 |
|
| 11 | 12 |
bundle_test_integration 2>&1 | tee $DEST/test.log |