ruma / homeserver

A Matrix homeserver written in Rust.

Home Page:https://www.ruma.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create test database and run migrations from Rust

jimmycuadra opened this issue · comments

I'd like to support a workflow where Ruma can be developed with only Docker Compose, not requiring Postgres, diesel-cli, or even Rust to be installed on the host computer.

Right now the procedure for running the test suite looks like this:

  1. cargo test --no-run to make sure there are no compilation errors before starting the heavy machinery.
  2. Start the test database in a Docker container.
  3. Run diesel-cli's commands to create the database and run the migrations.
  4. cargo test

A better flow would be to have the test code itself manage the creation (or drop and recreation) of the test database and migrations. Then everything could be wired up with Docker Compose and there could be a script that did something like docker-compose run --rm cargo test, which would start a dependent "postgres" service, but not require any external tooling to manage stuff.

In order to do this nicely, it'll be necessary for diesel_cli's database setup functionality to be exposed via a Rust API. See diesel-rs/diesel#357

This is done, but I'm gonna leave this issue open so that the internals of the test module can be cleaned up a bit in the event that diesel_cli adds a public API as mentioned in the comment above.