test-unit 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. set -e
  3. DEST=$1
  4. RED=$'\033[31m'
  5. GREEN=$'\033[32m'
  6. TEXTRESET=$'\033[0m' # reset the foreground colour
  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-unit
  12. #
  13. bundle_test_unit() {
  14. {
  15. date
  16. # Run all the tests if no TESTDIRS were specified.
  17. if [ -z "$TESTDIRS" ]; then
  18. TESTDIRS=$(find_dirs '*_test.go')
  19. fi
  20. TESTS_FAILED=()
  21. for test_dir in $TESTDIRS; do
  22. echo
  23. if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER" go_test_dir "$test_dir"; then
  24. TESTS_FAILED+=("$test_dir")
  25. echo
  26. echo "${RED}Tests failed: $test_dir${TEXTRESET}"
  27. sleep 1 # give it a second, so observers watching can take note
  28. fi
  29. done
  30. echo
  31. echo
  32. echo
  33. # if some tests fail, we want the bundlescript to fail, but we want to
  34. # try running ALL the tests first, hence TESTS_FAILED
  35. if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then
  36. echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}"
  37. echo
  38. false
  39. else
  40. echo "${GREEN}Test success${TEXTRESET}"
  41. echo
  42. true
  43. fi
  44. } 2>&1 | tee $DEST/test.log
  45. }
  46. bundle_test_unit