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 reddit.com/r/golang

Our great sponsors
  • Scout APM - Less time debugging, more time building
  • SonarQube - Static code analysis for 29 languages.
  • OPS - Build and Run Open Source Unikernels
  • GitHub repo 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.

  • GitHub repo 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//

  • Scout APM

    Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.

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

  • GitHub repo 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

  • GitHub repo 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/

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