database

package
v0.0.0-...-04a8f6c Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package database provides test database utilities and helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestClient

func NewTestClient(t *testing.T) *database.Client

NewTestClient creates a test database client. In CI (when CI_DATABASE_URL is set): connects to external PostgreSQL service container. In local dev: spins up a testcontainer with PostgreSQL. The container/connection is automatically cleaned up when the test ends.

Types

type SharedTestDB

type SharedTestDB struct {
	// contains filtered or unexported fields
}

SharedTestDB creates a single PostgreSQL schema that can be shared by multiple test replicas. Each replica gets its own connection pool via NewClient, but all pools point to the same schema — enabling cross-replica tests that exercise PostgreSQL NOTIFY/LISTEN event delivery.

func NewSharedTestDB

func NewSharedTestDB(t *testing.T) *SharedTestDB

NewSharedTestDB creates a shared test schema, runs migrations and GIN indexes once, and registers t.Cleanup to drop the schema. Call NewClient to create independent database clients for each replica.

func (*SharedTestDB) NewClient

func (s *SharedTestDB) NewClient(t *testing.T) *database.Client

NewClient creates an independent *database.Client backed by a fresh connection pool to the shared schema. Each client has its own pool so replicas can be shut down independently without races. The client's connections are closed via t.Cleanup.

Jump to

Keyboard shortcuts

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