1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/hack/make/.integration-test-helpers
Vincent Demeester 6b025a8b66 Introduce test-integration target (and deprecate/freeze test-integration-cli)
This adds a new package `integration` where `engine` integration tests
should live. Those integration tests should not depends on any `cli`
components (except from the `dockerd` daemon for now — to actually
start a daemon).

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2017-08-09 11:02:57 -04:00

103 lines
2.7 KiB
Bash

#!/usr/bin/env bash
: ${TEST_REPEAT:=0}
bundle_test_integration_cli() {
TESTFLAGS="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -test.timeout=360m"
go_test_dir integration-cli $DOCKER_INTEGRATION_TESTS_VERIFIED
}
bundle_test_integration() {
TESTFLAGS="$TESTFLAGS -v -test.timeout=60m"
(
set -e
cd integration
INCBUILD="-i"
count=0
for flag in "${BUILDFLAGS[@]}"; do
if [ "${flag}" == ${INCBUILD} ]; then
unset BUILDFLAGS[${count}]
break
fi
count=$[ ${count} + 1 ]
done
echo go test -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS ./...
go test -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS ./...
)
}
# 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-cli
#
go_test_dir() {
dir=$1
precompiled=$2
testbinary="$ABS_DEST/test.main"
testcover=()
testcoverprofile=()
(
set -e
mkdir -p "$DEST/coverprofiles"
export DEST="$ABS_DEST" # in a subshell this is safe -- our integration-cli tests need DEST, and "cd" screws it up
if [ -z $precompiled ]; then
ensure_test_dir $1 $testbinary
fi
cd "$dir"
i=0
while ((++i)); do
test_env "$testbinary" $TESTFLAGS
if [ $i -gt "$TEST_REPEAT" ]; then
break
fi
echo "Repeating test ($i)"
done
)
}
ensure_test_dir() {
(
# make sure a test dir will compile
dir="$1"
out="$2"
echo Building test dir: "$dir"
set -xe
cd "$dir"
go test -c -o "$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}"
)
}
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" \
"$@"
)
}