test_export_data_command.sh 1.9 KB

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