run-dbtests 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. DAK_ROOT="$(cd $(dirname "$0")/..; pwd)"
  8. export PGDATABASE=test_projectb
  9. if [[ ! -v DAK_INTEGRATION_TEST ]]; then
  10. SYS_CMD="sudo"
  11. KEEP_ENV_OPT="-E"
  12. USER_CMD="sudo -u dak PGDATABASE=${PGDATABASE} DAKBASE=${DAKBASE}"
  13. else
  14. SYS_CMD=""
  15. KEEP_ENV_OPT=""
  16. USER_CMD=""
  17. fi
  18. test-setup() {
  19. # Create the database as expected by the tests
  20. export DAKBASE=${DAK_ROOT}/tests/fixtures/tmpdak
  21. ${DAK_ROOT}/setup/dak-setup.sh
  22. }
  23. test-cleanup() {
  24. echo Dropping DB ${PGDATABASE}
  25. $USER_CMD $KEEP_ENV_OPT dropdb ${PGDATABASE}
  26. echo Deleting temporary directory
  27. $SYS_CMD rm -rf -- ${DAKBASE}
  28. }
  29. # Unless --nocleanup is passed, the script will cleanup at the end.
  30. if [[ "$1" != "--nocleanup" ]]; then
  31. trap test-cleanup EXIT
  32. fi
  33. test-setup
  34. $USER_CMD ${DAK_ROOT}/tests/dbtest_all.py