moby--moby/hack/make/.integration-test-helpers

88 lines
2.4 KiB
Bash

#!/usr/bin/env bash
source "$SCRIPTDIR/make/.go-autogen"
: ${TEST_REPEAT:=0}
bundle_test_integration() {
(
local flags="-v -test.timeout=${TIMEOUT} $TESTFLAGS"
cd integration
set -ex
# TODO: run existing binary?
go test -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $flags ./...
)
(
local flags="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -test.timeout=360m"
go_test_dir integration-cli
)
}
build_test_suite_binaries() {
build_test_suite_binary integration-cli "test.main"
for dir in $(find integration -type d); do
build_test_suite_binary "$dir" "test.main"
done
}
# Build a binary for a test suite package
build_test_suite_binary() {
local dir="$1"
local out="$2"
echo Building test suite binary "$dir/$out"
go test -c -o "$dir/$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" "./$dir"
}
# 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, e.g.
#
# TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit
#
# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want
# to run certain tests on your local host, you should run with command:
#
# TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration
#
go_test_dir() {
local dir=$1
(
set -e
# DEST is used by the test suite
export DEST="$ABS_DEST"
cd "$dir"
for i in $(seq 0 $TEST_REPEAT); do
echo "Repeating integration-test ($i)"
test_env "./test.main" $TESTFLAGS
done
)
}
test_env() {
(
set -xe
# use "env -i" to tightly control the environment variables that bleed into the tests
env -i \
DEST="$DEST" \
DOCKER_CLI_VERSION="$DOCKER_CLI_VERSION" \
DOCKER_API_VERSION="$DOCKER_API_VERSION" \
DOCKER_INTEGRATION_DAEMON_DEST="$DOCKER_INTEGRATION_DAEMON_DEST" \
DOCKER_TLS_VERIFY="$DOCKER_TEST_TLS_VERIFY" \
DOCKER_CERT_PATH="$DOCKER_TEST_CERT_PATH" \
DOCKER_ENGINE_GOARCH="$DOCKER_ENGINE_GOARCH" \
DOCKER_GRAPHDRIVER="$DOCKER_GRAPHDRIVER" \
DOCKER_USERLANDPROXY="$DOCKER_USERLANDPROXY" \
DOCKER_HOST="$DOCKER_HOST" \
DOCKER_REMAP_ROOT="$DOCKER_REMAP_ROOT" \
DOCKER_REMOTE_DAEMON="$DOCKER_REMOTE_DAEMON" \
DOCKERFILE="$DOCKERFILE" \
GOPATH="$GOPATH" \
GOTRACEBACK=all \
HOME="$ABS_DEST/fake-HOME" \
PATH="$PATH" \
TEMP="$TEMP" \
TEST_IMAGE_NAMESPACE="$TEST_IMAGE_NAMESPACE" \
TEST_CLIENT_BINARY="$TEST_CLIENT_BINARY" \
"$@"
)
}