run-dbtests 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. set -e
  3. # Create the database that will be used by the fixtures, populating it with the
  4. # default data. Also create a test dak directory.
  5. # After that, run all dbtests
  6. # At the end, clean up.
  7. if [[ ! -v DAK_ROOT ]]; then
  8. DAK_ROOT="$(cd $(dirname "$0")/..; pwd)"
  9. fi
  10. export PGDATABASE=test_projectb
  11. if [[ ! -v DAK_INTEGRATION_TEST ]]; then
  12. SYS_CMD="sudo"
  13. KEEP_ENV_OPT="-E"
  14. USER_CMD="sudo -u dak PGDATABASE=${PGDATABASE} DAKBASE=${DAKBASE}"
  15. PYTHON_COVERAGE=
  16. else
  17. SYS_CMD=""
  18. KEEP_ENV_OPT=""
  19. USER_CMD=""
  20. if [ "$RUN_COVERAGE" = "y" ]; then
  21. PYTHON_COVERAGE="python3-coverage run --rcfile ${DAK_ROOT}/.coveragerc --parallel-mode"
  22. else
  23. PYTHON_COVERAGE=
  24. fi
  25. fi
  26. test-setup() {
  27. # Create the database as expected by the tests
  28. export DAKBASE=$(mktemp -d)
  29. export HOME="${DAKBASE}/home"
  30. ${DAK_ROOT}/setup/dak-setup.sh
  31. mkdir "$HOME" || exit $?
  32. }
  33. test-cleanup() {
  34. echo Dropping DB ${PGDATABASE}
  35. $USER_CMD $KEEP_ENV_OPT dropdb ${PGDATABASE}
  36. echo Deleting temporary directory
  37. $SYS_CMD rm -rf -- ${DAKBASE}
  38. }
  39. # Unless --nocleanup is passed, the script will cleanup at the end.
  40. if [[ "$1" != "--nocleanup" ]]; then
  41. trap test-cleanup EXIT
  42. fi
  43. test-setup
  44. $USER_CMD $PYTHON_COVERAGE ${DAK_ROOT}/tests/dbtest_all.py