test 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. DEST=$1
  3. set -e
  4. TEXTRESET=$'\033[0m' # reset the foreground colour
  5. RED=$'\033[31m'
  6. GREEN=$'\033[32m'
  7. # Run Docker's test suite, including sub-packages, and store their output as a bundle
  8. # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
  9. # You can use this to select certain tests to run, eg.
  10. #
  11. # TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test
  12. #
  13. bundle_test() {
  14. {
  15. date
  16. TESTS_FAILED=()
  17. for test_dir in $(find_test_dirs); do
  18. echo
  19. if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir "$test_dir"; then
  20. TESTS_FAILED+=("$test_dir")
  21. echo
  22. echo "${RED}Tests failed: $test_dir${TEXTRESET}"
  23. sleep 1 # give it a second, so observers watching can take note
  24. fi
  25. done
  26. echo
  27. echo
  28. echo
  29. # if some tests fail, we want the bundlescript to fail, but we want to
  30. # try running ALL the tests first, hence TESTS_FAILED
  31. if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then
  32. echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}"
  33. echo
  34. false
  35. else
  36. echo "${GREEN}Test success${TEXTRESET}"
  37. echo
  38. true
  39. fi
  40. } 2>&1 | tee $DEST/test.log
  41. }
  42. # This helper function walks the current directory looking for directories
  43. # holding Go test files, and prints their paths on standard output, one per
  44. # line.
  45. find_test_dirs() {
  46. find -not \( \
  47. \( -wholename './vendor' -o -wholename './integration' \) \
  48. -prune \
  49. \) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u
  50. }
  51. bundle_test