What is the fastest way to clear my SQL database between integration tests?

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • schemata

    Helper methods for creating test schemas in PostgreSQL databases with copies of tables from the live schema for unit testing.

  • 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.

  • txdriver

    txdriver provides transaction isolation for Go SQL tests

  • I do option 1 and it can be super fast. Here's my implementation of it: https://github.com/bouk/txdriver//

  • 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.

    WorkOS logo
  • sql-migrate

    SQL schema migration tool for Go.

  • 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.

  • krok

    The main server of the hook management system

  • 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

  • dockertest

    Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.

  • I'm amazed that no-one is suggesting this gem: https://github.com/ory/dockertest/

  • 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.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts