sqltest

package
v0.9.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 21 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOrReplace added in v0.5.0

func CreateOrReplace(t testing.TB, u url.URL, dbName string, template string) url.URL

CreateOrReplace creates a new database with the given name (optionally from template), and schedules it to be dropped after test completion.

func NewDB added in v0.5.0

func NewDB(t testing.TB, dbURL string) *sqlx.DB

NewDB returns a new test database for the given URL.

func NewInMemoryDataSource

func NewInMemoryDataSource(t *testing.T) sqlutil.DataSource

NewInMemoryDataSource returns a new in-memory DataSource

func NewNoOpDataSource

func NewNoOpDataSource() sqlutil.DataSource

NewNoOpDataSource returns an empty DataSource type which will satisfy the interface

func RegisterTxDB added in v0.5.0

func RegisterTxDB(dbURL string) error

txdb is a simplified version of https://github.com/DATA-DOG/go-txdb

The original lib has various problems and is hard to understand because it tries to be more general. The version in this file is more tightly focused to our needs and should be easier to reason about and less likely to have subtle bugs/races.

It doesn't currently support savepoints but could be made to if necessary.

Transaction BEGIN/ROLLBACK effectively becomes a no-op, this should have no negative impact on normal test operation.

If you MUST test BEGIN/ROLLBACK behaviour, you will have to configure your store to use the raw DialectPostgres dialect and setup a one-use database. See heavyweight.FullTestDB() as a convenience function to help you do this, but please use sparingly because as it's name implies, it is expensive.

func SkipInMemory added in v0.5.0

func SkipInMemory(t *testing.T)

SkipInMemory skips the test when using an in-memory database.

func TestURL added in v0.5.0

func TestURL(t testing.TB) string

TestURL returns a database URL for this test. It may be external (if configured) or in-memory.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL