Our great sponsors
-
schemata
Helper methods for creating test schemas in PostgreSQL databases with copies of tables from the live schema for unit testing.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
dockertest
Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
I wrote something to copy the production schema into a test schema. I could then load test data, run tests, and then drop the schema.
I do option 1 and it can be super fast. Here's my implementation of it: https://github.com/bouk/txdriver//
Keep your migrations in the code repo and use a tool like sql-migrate to automatically apply them for you. At my job, we run a new container for each package's tests, and create a new db with the migration scripts for every test. It's certainly a bit slower, but the reproducibility is worth it.
This creates a temporary database in a docker container while you are running your test. For an example look here: https://github.com/krok-o/krok/blob/main/tests/livestore/init_test.go
I'm amazed that no-one is suggesting this gem: https://github.com/ory/dockertest/