Skip to content

Commit

Permalink
Merge pull request moby#3132 from tianon/hack-separate-integration
Browse files Browse the repository at this point in the history
Separate Integration Tests
  • Loading branch information
tianon committed Dec 13, 2013
2 parents b8a16b3 + f0879a1 commit 23ab0af
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions hack/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ grep -q "$RESOLVCONF" /proc/mounts || {
DEFAULT_BUNDLES=(
binary
test
test-integration
dynbinary
dyntest
dyntest-integration
tgz
ubuntu
)
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions hack/make/dynbinary
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
57 changes: 5 additions & 52 deletions hack/make/dyntest
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
17 changes: 17 additions & 0 deletions hack/make/dyntest-integration
Original file line number Diff line number Diff line change
@@ -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"
)
32 changes: 13 additions & 19 deletions hack/make/test
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
{
Expand All @@ -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
Expand All @@ -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
11 changes: 11 additions & 0 deletions hack/make/test-integration
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 23ab0af

Please sign in to comment.