github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/hack/make/.integration-test-helpers (about) 1 #!/usr/bin/env bash 2 # 3 # For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want 4 # to run certain tests on your local host, you should run with command: 5 # 6 # TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration 7 # 8 if [ -z $MAKEDIR ]; then 9 export MAKEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 10 fi 11 source "$MAKEDIR/.go-autogen" 12 13 # Set defaults 14 : ${TEST_REPEAT:=1} 15 : ${TESTFLAGS:=} 16 : ${TESTDEBUG:=} 17 18 integration_api_dirs=${TEST_INTEGRATION_DIR:-"$( 19 find ./integration -type d | 20 grep -vE '(^./integration($|/util)|/testdata)')"} 21 22 run_test_integration() { 23 [[ "$TESTFLAGS" != *-check.f* ]] && run_test_integration_suites 24 run_test_integration_legacy_suites 25 } 26 27 run_test_integration_suites() { 28 local flags="-test.v -test.timeout=${TIMEOUT} $TESTFLAGS" 29 for dir in $integration_api_dirs; do 30 if ! ( 31 cd $dir 32 echo "Running $PWD" 33 test_env ./test.main $flags 34 ); then exit 1; fi 35 done 36 } 37 38 run_test_integration_legacy_suites() { 39 ( 40 flags="-check.v -check.timeout=${TIMEOUT} -test.timeout=360m $TESTFLAGS" 41 cd integration-cli 42 echo "Running $PWD" 43 test_env ./test.main $flags 44 ) 45 } 46 47 build_test_suite_binaries() { 48 if [ ${DOCKER_INTEGRATION_TESTS_VERIFIED-} ]; then 49 echo "Skipping building test binaries; as DOCKER_INTEGRATION_TESTS_VERIFIED is set" 50 return 51 fi 52 build_test_suite_binary ./integration-cli "test.main" 53 for dir in $integration_api_dirs; do 54 build_test_suite_binary "$dir" "test.main" 55 done 56 } 57 58 # Build a binary for a test suite package 59 build_test_suite_binary() { 60 local dir="$1" 61 local out="$2" 62 echo Building test suite binary "$dir/$out" 63 go test -c -o "$dir/$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" "$dir" 64 } 65 66 cleanup_test_suite_binaries() { 67 [ -n "$TESTDEBUG" ] && return 68 echo "Removing test suite binaries" 69 find integration* -name test.main | xargs -r rm 70 } 71 72 repeat() { 73 for i in $(seq 1 $TEST_REPEAT); do 74 echo "Running integration-test (iteration $i)" 75 $@ 76 done 77 } 78 79 # use "env -i" to tightly control the environment variables that bleed into the tests 80 test_env() { 81 ( 82 set -e 83 [ -n "$TESTDEBUG" ] && set -x 84 env -i \ 85 DEST="$ABS_DEST" \ 86 DOCKER_API_VERSION="$DOCKER_API_VERSION" \ 87 DOCKER_INTEGRATION_DAEMON_DEST="$DOCKER_INTEGRATION_DAEMON_DEST" \ 88 DOCKER_TLS_VERIFY="$DOCKER_TEST_TLS_VERIFY" \ 89 DOCKER_CERT_PATH="$DOCKER_TEST_CERT_PATH" \ 90 DOCKER_ENGINE_GOARCH="$DOCKER_ENGINE_GOARCH" \ 91 DOCKER_GRAPHDRIVER="$DOCKER_GRAPHDRIVER" \ 92 DOCKER_USERLANDPROXY="$DOCKER_USERLANDPROXY" \ 93 DOCKER_HOST="$DOCKER_HOST" \ 94 DOCKER_REMAP_ROOT="$DOCKER_REMAP_ROOT" \ 95 DOCKER_REMOTE_DAEMON="$DOCKER_REMOTE_DAEMON" \ 96 DOCKERFILE="$DOCKERFILE" \ 97 GOPATH="$GOPATH" \ 98 GOTRACEBACK=all \ 99 HOME="$ABS_DEST/fake-HOME" \ 100 PATH="$PATH" \ 101 TEMP="$TEMP" \ 102 TEST_IMAGE_NAMESPACE="$TEST_IMAGE_NAMESPACE" \ 103 TEST_CLIENT_BINARY="$TEST_CLIENT_BINARY" \ 104 "$@" 105 ) 106 } 107 108 109 error_on_leaked_containerd_shims() { 110 if [ "$(go env GOOS)" == 'windows' ]; then 111 return 112 fi 113 114 leftovers=$(ps -ax -o pid,cmd | 115 awk '$2 == "docker-containerd-shim" && $4 ~ /.*\/bundles\/.*\/test-integration/ { print $1 }') 116 if [ -n "$leftovers" ]; then 117 ps aux 118 kill -9 $leftovers 2> /dev/null 119 echo "!!!! WARNING you have left over shim(s), Cleanup your test !!!!" 120 exit 1 121 fi 122 }