Package coverage when running integration tests
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)
This commit is contained in:
parent
d0f4bc7cca
commit
b3d5e9527a
13
hack/make.sh
13
hack/make.sh
|
@ -101,13 +101,14 @@ fi
|
||||||
#
|
#
|
||||||
go_test_dir() {
|
go_test_dir() {
|
||||||
dir=$1
|
dir=$1
|
||||||
|
coverpkg=$2
|
||||||
testcover=()
|
testcover=()
|
||||||
if [ "$HAVE_GO_TEST_COVER" ]; then
|
if [ "$HAVE_GO_TEST_COVER" ]; then
|
||||||
# if our current go install has -cover, we want to use it :)
|
# if our current go install has -cover, we want to use it :)
|
||||||
mkdir -p "$DEST/coverprofiles"
|
mkdir -p "$DEST/coverprofiles"
|
||||||
coverprofile="docker${dir#.}"
|
coverprofile="docker${dir#.}"
|
||||||
coverprofile="$DEST/coverprofiles/${coverprofile//\//-}"
|
coverprofile="$DEST/coverprofiles/${coverprofile//\//-}"
|
||||||
testcover=( -cover -coverprofile "$coverprofile" )
|
testcover=( -cover -coverprofile "$coverprofile" $coverpkg )
|
||||||
fi
|
fi
|
||||||
(
|
(
|
||||||
set -x
|
set -x
|
||||||
|
@ -116,6 +117,16 @@ go_test_dir() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This helper function walks the current directory looking for directories
|
||||||
|
# holding certain files ($1 parameter), and prints their paths on standard
|
||||||
|
# output, one per line.
|
||||||
|
find_dirs() {
|
||||||
|
find -not \( \
|
||||||
|
\( -wholename './vendor' -o -wholename './integration' -o -wholename './contrib' -o -wholename './pkg/mflag/example' \) \
|
||||||
|
-prune \
|
||||||
|
\) -name "$1" -print0 | xargs -0n1 dirname | sort -u
|
||||||
|
}
|
||||||
|
|
||||||
bundle() {
|
bundle() {
|
||||||
bundlescript=$1
|
bundlescript=$1
|
||||||
bundle=$(basename $bundlescript)
|
bundle=$(basename $bundlescript)
|
||||||
|
|
|
@ -19,7 +19,7 @@ bundle_test() {
|
||||||
date
|
date
|
||||||
|
|
||||||
TESTS_FAILED=()
|
TESTS_FAILED=()
|
||||||
for test_dir in $(find_test_dirs); do
|
for test_dir in $(find_dirs '*_test.go'); do
|
||||||
echo
|
echo
|
||||||
|
|
||||||
if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir "$test_dir"; then
|
if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir "$test_dir"; then
|
||||||
|
@ -48,15 +48,4 @@ bundle_test() {
|
||||||
} 2>&1 | tee $DEST/test.log
|
} 2>&1 | tee $DEST/test.log
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# This helper function walks the current directory looking for directories
|
|
||||||
# holding Go test files, and prints their paths on standard output, one per
|
|
||||||
# line.
|
|
||||||
find_test_dirs() {
|
|
||||||
find -not \( \
|
|
||||||
\( -wholename './vendor' -o -wholename './integration' \) \
|
|
||||||
-prune \
|
|
||||||
\) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u
|
|
||||||
}
|
|
||||||
|
|
||||||
bundle_test
|
bundle_test
|
||||||
|
|
|
@ -5,7 +5,8 @@ DEST=$1
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
bundle_test_integration() {
|
bundle_test_integration() {
|
||||||
LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir ./integration
|
LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir ./integration \
|
||||||
|
"-coverpkg $(find_dirs '*.go' | sed 's,^\.,github.com/dotcloud/docker,g' | paste -d, -s)"
|
||||||
}
|
}
|
||||||
|
|
||||||
bundle_test_integration 2>&1 | tee $DEST/test.log
|
bundle_test_integration 2>&1 | tee $DEST/test.log
|
||||||
|
|
Loading…
Reference in New Issue