test_export_data_command.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. # Test for the export-data admin command against sqlite and postgres
  3. set -xe
  4. cd "$(dirname "$0")/../.."
  5. echo "--- Install dependencies"
  6. # Install dependencies for this test.
  7. pip install psycopg2
  8. # Install Synapse itself. This won't update any libraries.
  9. pip install -e .
  10. echo "--- Generate the signing key"
  11. # Generate the server's signing key.
  12. python -m synapse.app.homeserver --generate-keys -c .ci/sqlite-config.yaml
  13. echo "--- Prepare test database"
  14. # Make sure the SQLite3 database is using the latest schema and has no pending background update.
  15. scripts/update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
  16. # Run the export-data command on the sqlite test database
  17. python -m synapse.app.admin_cmd -c .ci/sqlite-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
  18. --output-directory /tmp/export_data
  19. # Test that the output directory exists and contains the rooms directory
  20. dir="/tmp/export_data/rooms"
  21. if [ -d "$dir" ]; then
  22. echo "Command successful, this test passes"
  23. else
  24. echo "No output directories found, the command fails against a sqlite database."
  25. exit 1
  26. fi
  27. # Create the PostgreSQL database.
  28. .ci/scripts/postgres_exec.py "CREATE DATABASE synapse"
  29. # Port the SQLite databse to postgres so we can check command works against postgres
  30. echo "+++ Port SQLite3 databse to postgres"
  31. scripts/synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
  32. # Run the export-data command on postgres database
  33. python -m synapse.app.admin_cmd -c .ci/postgres-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
  34. --output-directory /tmp/export_data2
  35. # Test that the output directory exists and contains the rooms directory
  36. dir2="/tmp/export_data2/rooms"
  37. if [ -d "$dir2" ]; then
  38. echo "Command successful, this test passes"
  39. else
  40. echo "No output directories found, the command fails against a postgres database."
  41. exit 1
  42. fi