.integration-test-helpers 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env bash
  2. : ${TEST_REPEAT:=0}
  3. bundle_test_integration_cli() {
  4. TESTFLAGS="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -test.timeout=360m"
  5. go_test_dir integration-cli $DOCKER_INTEGRATION_TESTS_VERIFIED
  6. }
  7. # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
  8. # You can use this to select certain tests to run, e.g.
  9. #
  10. # TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit
  11. #
  12. # For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want
  13. # to run certain tests on your local host, you should run with command:
  14. #
  15. # TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration-cli
  16. #
  17. go_test_dir() {
  18. dir=$1
  19. precompiled=$2
  20. testbinary="$ABS_DEST/test.main"
  21. testcover=()
  22. testcoverprofile=()
  23. (
  24. set -e
  25. mkdir -p "$DEST/coverprofiles"
  26. export DEST="$ABS_DEST" # in a subshell this is safe -- our integration-cli tests need DEST, and "cd" screws it up
  27. if [ -z $precompiled ]; then
  28. ensure_test_dir $1 $testbinary
  29. fi
  30. cd "$dir"
  31. i=0
  32. while ((++i)); do
  33. test_env "$testbinary" $TESTFLAGS
  34. if [ $i -gt "$TEST_REPEAT" ]; then
  35. break
  36. fi
  37. echo "Repeating test ($i)"
  38. done
  39. )
  40. }
  41. ensure_test_dir() {
  42. (
  43. # make sure a test dir will compile
  44. dir="$1"
  45. out="$2"
  46. echo Building test dir: "$dir"
  47. set -xe
  48. cd "$dir"
  49. go test -c -o "$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}"
  50. )
  51. }
  52. test_env() {
  53. (
  54. set -xe
  55. # use "env -i" to tightly control the environment variables that bleed into the tests
  56. env -i \
  57. DEST="$DEST" \
  58. DOCKER_CLI_VERSION="$DOCKER_CLI_VERSION" \
  59. DOCKER_API_VERSION="$DOCKER_API_VERSION" \
  60. DOCKER_INTEGRATION_DAEMON_DEST="$DOCKER_INTEGRATION_DAEMON_DEST" \
  61. DOCKER_TLS_VERIFY="$DOCKER_TEST_TLS_VERIFY" \
  62. DOCKER_CERT_PATH="$DOCKER_TEST_CERT_PATH" \
  63. DOCKER_ENGINE_GOARCH="$DOCKER_ENGINE_GOARCH" \
  64. DOCKER_GRAPHDRIVER="$DOCKER_GRAPHDRIVER" \
  65. DOCKER_USERLANDPROXY="$DOCKER_USERLANDPROXY" \
  66. DOCKER_HOST="$DOCKER_HOST" \
  67. DOCKER_REMAP_ROOT="$DOCKER_REMAP_ROOT" \
  68. DOCKER_REMOTE_DAEMON="$DOCKER_REMOTE_DAEMON" \
  69. DOCKERFILE="$DOCKERFILE" \
  70. GOPATH="$GOPATH" \
  71. GOTRACEBACK=all \
  72. HOME="$ABS_DEST/fake-HOME" \
  73. PATH="$PATH" \
  74. TEMP="$TEMP" \
  75. TEST_IMAGE_NAMESPACE="$TEST_IMAGE_NAMESPACE" \
  76. TEST_CLIENT_BINARY="$TEST_CLIENT_BINARY" \
  77. "$@"
  78. )
  79. }