Brrr is an integration testing thingy for go applications using postgres.
- Launches a single go test container for postgres.
- Optionally runs seeding migration scripts.
- Marks the database as a template database.
- For each test, creates a new database from the template so each test can have its own database in isolation.
- Runs isolated integration tests in parallel.
It goes fast.
var c *brrr.Container
func TestMain(m *testing.M) {
cfg := brrr.Config {
User: "postgres",
Password: "test",
Database: "acme",
}
var err error
c, err = brrr.NewContainer(cfg)
if err != nil {
log.Fatalf("failed to create test container: %v", err)
}
defer c.Close()
exitCode := m.Run()
os.Exit(exitCode)
}
func TestSomething(t *testing.T) {
t.Parallel()
db, err := c.NewInstance(t.Context())
if err != nil {
t.Fatal(err)
}
defer c.CloseInstance(t.Context(), db)
err = db.Connection.Ping(t.Context())
if err != nil {
t.Fatalf("failed to ping database: %v", err)
}
}