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

testpostgres

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testpostgres provisions a Postgres backend for store tests.

It is test-only support code and intentionally the ONLY place in the store tree that imports testcontainers, keeping that heavy, Docker-bound dependency out of the shipped server binary's dependency graph.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnavailable = errors.New("no postgres test backend available")

ErrUnavailable means no Postgres backend could be provisioned: neither STACKIT_TEST_DATABASE_URL is set nor could a throwaway container start. Callers should t.Skip on this so the suite stays green without Docker.

Functions

This section is empty.

Types

type Harness

type Harness struct {
	URL string
	// contains filtered or unexported fields
}

Harness owns the connection string for store tests and serializes access so parallel tests don't observe each other's rows.

func Start

func Start(ctx context.Context) (*Harness, error)

Start provisions a backend. Precedence:

  1. STACKIT_TEST_DATABASE_URL (e.g. a CI service container) — used directly.
  2. A throwaway testcontainer (local dev with a running Docker daemon).

It returns ErrUnavailable when neither is possible.

func (*Harness) Reset

func (h *Harness) Reset(t testing.TB)

Reset drops the store's tables so the next store.Open re-runs migrations against an empty schema. It holds an exclusive lock for the duration of the calling test, serializing DB access across parallel tests.

func (*Harness) Terminate

func (h *Harness) Terminate(ctx context.Context) error

Terminate releases a container-backed harness. External-DB harnesses are a no-op.

Jump to

Keyboard shortcuts

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