sqlxtest

package
v0.1.95 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sqlxtest runs a store's test suite against every SQL dialect.

Before the sqlx adapter existed, each store was written twice and only the SQLite half was tested: 18 of 22 PostgreSQL store implementations had no test that touched a database. A single implementation behind sqlx.DB means one suite can cover both backends, so store tests should call Run rather than opening a *sql.DB directly.

SQLite always runs, in memory. PostgreSQL runs only when GOMODEL_TEST_POSTGRES_URL is set; otherwise that subtest skips. A set but unreachable URL fails the test rather than skipping, so CI cannot stay green while the server it started is not the one being tested. The variable is deliberately not POSTGRES_URL — pointing a suite that creates and drops schemas at a configured application database should take a separate, explicit opt-in.

Index

Constants

View Source
const PostgresURLEnv = "GOMODEL_TEST_POSTGRES_URL"

PostgresURLEnv names the environment variable holding the test PostgreSQL connection string.

Variables

This section is empty.

Functions

func NewPostgresPool

func NewPostgresPool(t *testing.T) *pgxpool.Pool

NewPostgresPool returns a connection pool scoped to a throwaway schema, or nil after skipping when no test server is configured.

Run is the right entry point for a store written against sqlx.DB. This is for the few tests that also need the raw pool — a store that has not moved onto sqlx yet takes *pgxpool.Pool directly, and a test spanning both wants them pointed at one schema.

func NewSQLite

func NewSQLite(t *testing.T) sqlx.DB

NewSQLite returns an empty in-memory SQLite database for one test.

func Run

func Run(t *testing.T, fn func(t *testing.T, db sqlx.DB))

Run executes fn once per available dialect, as a subtest named after it. Each run receives an empty database that is discarded afterwards.

Types

This section is empty.

Jump to

Keyboard shortcuts

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