Help us shape the future of Go! Take the 2026 Go Developer Survey

testdb

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testdb creates the database that one database case uses alone (the case database).

The database that ORM_TEST_MYSQL_DSN and ORM_TEST_POSTGRES_DSN point to is shared by several runs and sessions, so it cannot be assumed empty. Installing a schema or checking for an empty database A case creates its own database with New, and the database is deleted when the case ends (even after a failure). The shared DSN is used only as an admin connection and creates nothing in its database.

PostgreSQL also creates a database, not a schema. Empty() counts the non-public schemas by their content, so an empty database cannot be checked with a case schema inside a shared database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseOf

func DatabaseOf(t testing.TB, dsn string) string

DatabaseOf is the database name of a MySQL or PostgreSQL DSN.

func DirNames added in v0.0.19

func DirNames(t testing.TB, dir string) []string

DirNames returns the entry names of dir in the order of os.ReadDir; a failure fails the test.

func Name

func Name() string

Name returns the next case database name, orm_case_<pid>_<number>. For a case that cannot create a database, such as a case bound to one PgBouncer database, it is used as its table name.

func New

func New(t testing.TB, driver string) string

New creates a case database for the driver ("sqlite", "mysql", "postgres") and returns its DSN. For MySQL and PostgreSQL it creates the database orm_case_<pid>_<number> on the server of ORM_TEST_<DRIVER>_DSN and changes only the path of the DSN to that name (the query stays as it is). SQLite uses the new file orm-case-<pid>-<number>.sqlite in the OS temp directory. Creating and deleting it is reported as a STEP line of the case (testcase.Of) wrapping t, and deletion runs in t.Cleanup, so it runs even after the case fails. If deletion fails, the case fails with the database name.

func Open

func Open(t testing.TB, driver, dsn string) *sql.DB

Open opens the database of a MySQL or PostgreSQL client DSN with the native database/sql driver.

func Retarget

func Retarget(t testing.TB, dsn, name string) string

Retarget is the DSN with the path of dsn changed to the database name. Use it to open the case database on another server (replica) under the same name.

Types

This section is empty.

Jump to

Keyboard shortcuts

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