testing

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Overview

Package testing provides test utilities for the jobqueue package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDBForBackend added in v0.2.3

func NewDBForBackend(t testing.TB, backend Backend) *sql.DB

NewDBForBackend creates a new database connection for the given backend. For SQLite, it creates an in-memory database. For PostgreSQL, it connects to the test container and sets up the schema.

func NewInMemoryDB

func NewInMemoryDB(t testing.TB) *sql.DB

NewInMemoryDB creates a new in-memory SQLite database for testing with both classic queue and dedup queue schemas initialized.

func NewPostgresDB added in v0.2.3

func NewPostgresDB(t testing.TB) *sql.DB

NewPostgresDB creates a new PostgreSQL connection for testing. It skips the test if PostgreSQL is not available.

func NewQ

func NewQ(t testing.TB, opts queue.NewOpts) *queue.Queue

NewQ creates a new queue using an in-memory SQLite database for testing.

func NewQForBackend added in v0.2.3

func NewQForBackend(t testing.TB, opts queue.NewOpts, backend Backend) *queue.Queue

NewQForBackend creates a new queue using the specified backend for testing.

func PostgresAvailable added in v0.2.3

func PostgresAvailable() bool

PostgresAvailable returns true if PostgreSQL container is running and available.

func RunForAllBackends added in v0.2.3

func RunForAllBackends(t *testing.T, fn func(t *testing.T, backend Backend))

RunForAllBackends runs a test function for each available backend. This creates subtests named "sqlite" and "postgres".

func RunForAllBackendsB added in v0.2.3

func RunForAllBackendsB(b *testing.B, fn func(b *testing.B, backend Backend))

RunForAllBackendsB runs a benchmark function for each available backend.

func SetupPostgresContainer added in v0.2.3

func SetupPostgresContainer(ctx context.Context) error

SetupPostgresContainer initializes the PostgreSQL container. Call this from TestMain to set up the container once for all tests in a package.

func TeardownPostgresContainer added in v0.2.3

func TeardownPostgresContainer(ctx context.Context)

TeardownPostgresContainer terminates the PostgreSQL container. Call this from TestMain after m.Run() completes.

Types

type Backend added in v0.2.3

type Backend string

Backend represents a database backend for testing.

const (
	// BackendSQLite represents the SQLite backend.
	BackendSQLite Backend = "sqlite"
	// BackendPostgres represents the PostgreSQL backend.
	BackendPostgres Backend = "postgres"
)

func AllBackends added in v0.2.3

func AllBackends() []Backend

AllBackends returns all available backends for testing. PostgreSQL is excluded if not available (container not running or skipped).

func (Backend) Dialect added in v0.2.3

func (b Backend) Dialect() dialect.Dialect

Dialect returns the SQL dialect for this backend.

func (Backend) IsPostgres added in v0.2.3

func (b Backend) IsPostgres() bool

IsPostgres returns true if this is the PostgreSQL backend.

func (Backend) IsSQLite added in v0.2.3

func (b Backend) IsSQLite() bool

IsSQLite returns true if this is the SQLite backend.

type Logger

type Logger func(msg string, args ...any)

func NewLogger

func NewLogger(t *testing.T) Logger

func (Logger) Info

func (f Logger) Info(msg string, args ...any)

Jump to

Keyboard shortcuts

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