testdb

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package testdb provides a shared PostgreSQL test container for integration tests. It starts a single container per test binary (via sync.Once), runs goose migrations, and returns a connection pool ready for use.

Tests should use CreateTestFeature to create uniquely-named features and flags that are automatically cleaned up, enabling parallel test execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Require

func Require(tb testing.TB) (string, *pgxpool.Pool)

Require starts a PostgreSQL test container (once per binary), runs goose migrations, and returns a fresh connection pool. The pool is closed via tb.Cleanup.

Tables are NOT truncated; use CreateTestFeature to create isolated test fixtures that are cleaned up automatically per test.

Types

type FlagSpec added in v0.15.0

type FlagSpec struct {
	FlagType string // e.g. "BOOL", "STRING", "INT64", "DOUBLE"
}

FlagSpec describes one flag to create within a test feature.

type TestFeature added in v0.15.0

type TestFeature struct {
	FeatureID string
	FlagIDs   []string
}

TestFeature holds the feature_id and flag IDs created for a test.

func CreateTestFeature added in v0.15.0

func CreateTestFeature(t *testing.T, pool *pgxpool.Pool, specs []FlagSpec) *TestFeature

CreateTestFeature inserts a uniquely-named feature and its flags into the database. The feature_id is derived from t.Name() plus a sequence number, guaranteeing no collisions even when tests run in parallel.

Cleanup is registered via t.Cleanup to delete the feature, its flags, overrides, and audit log entries when the test finishes.

func (*TestFeature) FlagID added in v0.15.0

func (f *TestFeature) FlagID(fieldNum int) string

FlagID returns the flag_id for the given field number (1-based). Panics if fieldNum is out of range.

Jump to

Keyboard shortcuts

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