Merge pull request #3132 from tianon/hack-separate-integration

Separate Integration Tests
This commit is contained in:
Tianon Gravi 2013-12-13 10:55:49 -08:00
commit 23ab0af2ff
7 changed files with 71 additions and 74 deletions

View File

@ -14,7 +14,7 @@ docs:
docker build -t docker-docs docs && docker run -p 8000:8000 docker-docs
test: build
$(DOCKER_RUN_DOCKER) hack/make.sh test
$(DOCKER_RUN_DOCKER) hack/make.sh test test-integration
shell: build
$(DOCKER_RUN_DOCKER) bash

View File

@ -35,8 +35,10 @@ grep -q "$RESOLVCONF" /proc/mounts || {
DEFAULT_BUNDLES=(
binary
test
test-integration
dynbinary
dyntest
dyntest-integration
tgz
ubuntu
)
@ -62,6 +64,24 @@ LDFLAGS='-X main.GITCOMMIT "'$GITCOMMIT'" -X main.VERSION "'$VERSION'" -w'
LDFLAGS_STATIC='-X github.com/dotcloud/docker/utils.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"'
BUILDFLAGS='-tags netgo'
# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
# You can use this to select certain tests to run, eg.
#
# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test
#
go_test_dir() {
dir=$1
( # we run "go test -i" ouside the "set -x" to provde cleaner output
cd "$dir"
go test -i -ldflags "$LDFLAGS" $BUILDFLAGS
)
(
set -x
cd "$dir"
go test -ldflags "$LDFLAGS" $BUILDFLAGS $TESTFLAGS
)
}
bundle() {
bundlescript=$1
bundle=$(basename $bundlescript)

View File

@ -11,5 +11,7 @@ ln -sf dockerinit-$VERSION $DEST/dockerinit
export DOCKER_INITSHA1="$(sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
# exported so that "dyntest" can easily access it later without recalculating it
go build -o $DEST/docker-$VERSION -ldflags "$LDFLAGS -X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" $BUILDFLAGS ./docker
echo "Created binary: $DEST/docker-$VERSION"
(
export LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\""
source "$(dirname "$BASH_SOURCE")/binary"
)

View File

@ -10,55 +10,8 @@ if [ ! -x "$INIT" ]; then
false
fi
# Run Docker's test suite, including sub-packages, and store their output as a bundle
# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
# You can use this to select certain tests to run, eg.
#
# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test
#
bundle_test() {
{
date
TESTS_FAILED=()
for test_dir in $(find_test_dirs); do
echo
if ! (
set -x
cd $test_dir
# Install packages that are dependencies of the tests.
# Note: Does not run the tests.
go test -i -ldflags "$LDFLAGS" $BUILDFLAGS
# Run the tests with the optional $TESTFLAGS.
export TEST_DOCKERINIT_PATH=$DEST/../dynbinary/dockerinit-$VERSION
go test -ldflags "$LDFLAGS -X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" $BUILDFLAGS $TESTFLAGS
); then
TESTS_FAILED+=("$test_dir")
sleep 1 # give it a second, so observers watching can take note
fi
done
# if some tests fail, we want the bundlescript to fail, but we want to
# try running ALL the tests first, hence TESTS_FAILED
if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then
echo
echo "Test failures in: ${TESTS_FAILED[@]}"
false
fi
} 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 . -name '*_test.go' | grep -v '^./vendor' |
{ while read f; do dirname $f; done; } |
sort -u
}
bundle_test
(
export TEST_DOCKERINIT_PATH="$INIT"
export LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\""
source "$(dirname "$BASH_SOURCE")/test"
)

View File

@ -0,0 +1,17 @@
#!/bin/bash
DEST=$1
INIT=$DEST/../dynbinary/dockerinit-$VERSION
set -e
if [ ! -x "$INIT" ]; then
echo >&2 'error: dynbinary must be run before dyntest-integration'
false
fi
(
export TEST_DOCKERINIT_PATH="$INIT"
export LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\""
source "$(dirname "$BASH_SOURCE")/test-integration"
)

View File

@ -12,7 +12,7 @@ GREEN=$'\033[32m'
# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
# You can use this to select certain tests to run, eg.
#
# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test
# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test
#
bundle_test() {
{
@ -22,34 +22,27 @@ bundle_test() {
for test_dir in $(find_test_dirs); do
echo
if ! (
set -x
cd $test_dir
# Install packages that are dependencies of the tests.
# Note: Does not run the tests.
go test -i -ldflags "$LDFLAGS $LDFLAGS_STATIC" $BUILDFLAGS
# Run the tests with the optional $TESTFLAGS.
go test -ldflags "$LDFLAGS $LDFLAGS_STATIC" $BUILDFLAGS $TESTFLAGS
); then
if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir "$test_dir"; then
TESTS_FAILED+=("$test_dir")
echo
echo "${RED}Test Failed: $test_dir${TEXTRESET}"
echo
echo "${RED}Tests failed: $test_dir${TEXTRESET}"
sleep 1 # give it a second, so observers watching can take note
fi
done
echo
echo
echo
# if some tests fail, we want the bundlescript to fail, but we want to
# try running ALL the tests first, hence TESTS_FAILED
if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then
echo
echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}"
echo
false
else
echo
echo "${GREEN}Test success${TEXTRESET}"
echo
true
fi
} 2>&1 | tee $DEST/test.log
@ -60,9 +53,10 @@ bundle_test() {
# holding Go test files, and prints their paths on standard output, one per
# line.
find_test_dirs() {
find . -name '*_test.go' | grep -v '^./vendor' |
{ while read f; do dirname $f; done; } |
sort -u
find -not \( \
\( -wholename './vendor' -o -wholename './integration' \) \
-prune \
\) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u
}
bundle_test

View File

@ -0,0 +1,11 @@
#!/bin/bash
DEST=$1
set -e
bundle_test_integration() {
LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir ./integration
}
bundle_test_integration 2>&1 | tee $DEST/test.log