Categorygithub.com/pascaldekloe/sqltest
repositorypackage
1.1.0
Repository: https://github.com/pascaldekloe/sqltest.git
Documentation: pkg.go.dev

# README

SQL Test

… convenience library for the Go programming language. Tests can run isolated in a dedicated transaction. An automated rollback after each test keeps the data consistent and/or clean.

API

func init() {
	// database configuration
	sqltest.Setup("pgx", "host=localhost user=test database=postgres")
	// optional connect string override with an environment variable
	sqltest.EnvSetup("", "TEST_CONNECT_STRING")
}

func TestWithSQLInteraction(t *testing.T) {
	db := sqltest.NewTx(t)
	// install package variables
	DBExec = db.ExecContext
	DBQuery = db.QueryContext

	// test …

	// automatic rollback
}

This is free and unencumbered software released into the public domain.