Documentation
¶
Overview ¶
Package dbtest opens panel databases for tests: a SQLite file in the test's temporary directory by default, or a fresh PostgreSQL database when RDPANEL_TEST_PG_DSN is set, so the same suites run on both engines (CI runs the PostgreSQL pass against a postgres service container).
On PostgreSQL every test gets its own database cloned from a migrated template (CREATE DATABASE ... TEMPLATE), dropped when the test ends. The template is named after a digest of the migrations and reused across runs. The DSN's role needs CREATEDB.
Index ¶
Constants ¶
const EnvPostgresDSN = "RDPANEL_TEST_PG_DSN"
EnvPostgresDSN names the variable holding a PostgreSQL DSN (URL or keyword/value form) to run database tests against.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
Open returns a migrated database that is closed (and on PostgreSQL dropped) when the test ends.
func OpenEmpty ¶
OpenEmpty returns an unmigrated database (tests stepping through migrations). It is closed (and on PostgreSQL dropped) when the test ends.
func OpenSQLite ¶
OpenSQLite opens (without migrating) the SQLite database at path, closed when the test ends. For tests that are about SQLite specifics.
func PostgresDSN ¶
func PostgresDSN() string
PostgresDSN returns the PostgreSQL DSN tests run against ("" = SQLite).
func PostgresURL ¶
PostgresURL creates a fresh, migrated PostgreSQL database for the test (dropped when it ends) and returns its DSN, for tests that open the database themselves (through the config, for instance). Only call it when Postgres reports true.
Types ¶
This section is empty.