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

dbtest

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
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

func Open(t testing.TB) *db.DB

Open returns a migrated database that is closed (and on PostgreSQL dropped) when the test ends.

func OpenEmpty

func OpenEmpty(t testing.TB) *db.DB

OpenEmpty returns an unmigrated database (tests stepping through migrations). It is closed (and on PostgreSQL dropped) when the test ends.

func OpenSQLite

func OpenSQLite(t testing.TB, path string) *db.DB

OpenSQLite opens (without migrating) the SQLite database at path, closed when the test ends. For tests that are about SQLite specifics.

func Postgres

func Postgres() bool

Postgres reports whether tests run against PostgreSQL.

func PostgresDSN

func PostgresDSN() string

PostgresDSN returns the PostgreSQL DSN tests run against ("" = SQLite).

func PostgresURL

func PostgresURL(t testing.TB) string

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.

Jump to

Keyboard shortcuts

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