Просмотр исходного кода

Add integration suite

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin 8 лет назад
Родитель
Сommit
de46fb736d

+ 32 - 48
hack/make/.integration-test-helpers

@@ -1,29 +1,36 @@
 #!/usr/bin/env bash
 
-: ${TEST_REPEAT:=0}
+source "$SCRIPTDIR/make/.go-autogen"
 
-bundle_test_integration_cli() {
-	TESTFLAGS="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -test.timeout=360m"
-	go_test_dir integration-cli $DOCKER_INTEGRATION_TESTS_VERIFIED
-}
+: ${TEST_REPEAT:=0}
 
 bundle_test_integration() {
-	TESTFLAGS="$TESTFLAGS -v -test.timeout=60m"
 	(
-		set -e
+		local flags="-v -test.timeout=${TIMEOUT} $TESTFLAGS"
 		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 ./...
+		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'.
@@ -34,45 +41,22 @@ bundle_test_integration() {
 # 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
+#     TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration
 #
 go_test_dir() {
-	dir=$1
-	precompiled=$2
-	testbinary="$ABS_DEST/test.main"
-	testcover=()
-	testcoverprofile=()
+	local dir=$1
 	(
 		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
+		# DEST is used by the test suite
+		export DEST="$ABS_DEST"
 		cd "$dir"
-		i=0
-		while ((++i)); do
-			test_env "$testbinary" $TESTFLAGS
-			if [ $i -gt "$TEST_REPEAT" ]; then
-				break
-			fi
-			echo "Repeating test ($i)"
+		for i in $(seq 0 $TEST_REPEAT); do
+			echo "Repeating integration-test ($i)"
+			test_env "./test.main" $TESTFLAGS
 		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

+ 0 - 13
hack/make/build-integration-test-binary

@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-rm -rf "$DEST"
-DEST="$ABS_DEST/../test-integration"
-
-source "$SCRIPTDIR/make/.go-autogen"
-
-if [ -z $DOCKER_INTEGRATION_TESTS_VERIFIED ]; then
-	source ${MAKEDIR}/.integration-test-helpers
-	ensure_test_dir integration-cli "$DEST/test.main"
-	export DOCKER_INTEGRATION_TESTS_VERIFIED=1
-fi

+ 1 - 1
hack/make/test-integration

@@ -6,7 +6,7 @@ source hack/make/.integration-test-helpers
 
 # subshell so that we can export PATH without breaking other things
 (
-	bundle build-integration-cli-test-binary
+    build_test_suite_binaries
 
 	bundle .integration-daemon-start