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 ¶
- func DatabaseOf(t testing.TB, dsn string) string
- func DirNames(t testing.TB, dir string) []string
- func Name() string
- func New(t testing.TB, driver string) string
- func NewCorpus(t testing.TB, setPath string) string
- func NewCorpusDir(t testing.TB, setPath string) (string, string)
- func Open(t testing.TB, driver, dsn string) *sql.DB
- func Retarget(t testing.TB, dsn, name string) string
- type FlowmarkServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DatabaseOf ¶
DatabaseOf is the database name of a MySQL or PostgreSQL DSN.
func DirNames ¶ added in v0.0.19
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 ¶
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 NewCorpus ¶ added in v0.0.22
NewCorpus installs the documents of the dbspec set at setPath as a new corpus, starts the flowmark server of FLOWMARK on it and returns its markdown DSN. The server stops when the test ends (FCV-3).
func NewCorpusDir ¶ added in v0.0.22
NewCorpusDir is NewCorpus that also returns the directory of the corpus.
Types ¶
type FlowmarkServer ¶ added in v0.0.22
FlowmarkServer is a running flowmark server: its port, its token, and what it wrote to its standard error.
func StartFlowmark ¶ added in v0.0.22
func StartFlowmark(t testing.TB, bin, dir, corpus string) FlowmarkServer
StartFlowmark starts the flowmark at bin on the installed corpus at dir, named corpus. The server stops when the test ends, after every cleanup that the test registers later.