A Go library containing utilities that help when writing tests that use real SQL database servers.
This library is only intended for use as a test dependencies for projects within the Dogmatiq organization.
The primary feature is the NewDatabase()
function which creates a temporary
database that can be discarded at the end of each test.
The database products in the table below are currently supported. Some products are supported via multiple different Go SQL drivers.
Product | Supported Drivers | Notes |
---|---|---|
MySQL | mysql | — |
MariaDB | mysql | — |
PostgreSQL | pgx (preferred), postgres | — |
SQLite | sqlite3 | Embedded database, requires CGO |
The docker-stack.yml
file in this repository starts
services for each of the supported database products. These services are typically required to run the tests for any project that depends on dogmatiq/sqltest
.
The stack can be deployed using the following command:
curl https://raw.githubusercontent.com/dogmatiq/sqltest/main/docker-stack.yml | docker stack deploy dogmatiq-sqltest --compose-file -
Projects that depend on dogmatiq/sqltest
should use the go+sql
workflow. This workflow starts services for each of the supported
database products, and runs the tests both with and without CGO enabled.
The workflow is chosen by changing the repository definition in the Terraform configuration. To see an example, check the definition of dogmatiq/sqltest
itself, which uses this workflow.