Search code examples
swiftvapor

Deleting test database in Vapor 3


I want to write some integration tests for Vapor 3 server and I need to have clean Postgre database each time I run my tests. How can I achieve this? It seems migrations isn't the right way to go as they've been running once if database doesn't exist yet.


Solution

  • Have a look at https://github.com/raywenderlich/vapor-til/tree/master/Tests

    This requires a DB to be running before you run the tests, but it reverts all migrations at the start of each test run, which gives you a clean DB each time. (Specifically here)

    There's also a docker-compose.yml in the root directory for spinning up a completely isolated test environment on Linux