storetest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package storetest gives tests outside the store a fresh, migrated database, so that the backend a test runs against is chosen in one place rather than in every test file: Postgres when MAILRULES_TEST_POSTGRES_DSN is set (see pgtest), SQLite otherwise.

Index

Constants

This section is empty.

Variables

View Source
var Master = bytes.Repeat([]byte{0x5a}, 32)

Master is the master key the stores New and InDir return seal and open secrets with: a fixed 32-byte test key, never one a real install has. A test that hands the data directory to the daemon writes it as master.key (crypto.MasterKeyFile) or sets it as cfg.MasterKey, so the daemon opens what the test sealed.

Functions

func InDir

func InDir(t testing.TB, dir string) (*store.Store, *sql.DB)

InDir is New for a test that needs the database in a given data directory: one that later hands the directory to the daemon, or reopens it. The directory's database is migrated if it is not yet, and closed when the test ends.

InDir is always SQLite, whatever the DSN: it is the database a daemon opens in its data directory. A daemon test on Postgres hands the daemon a URL from pgtest instead.

func New

func New(t testing.TB) (*store.Store, *sql.DB)

New opens an empty, migrated database for the test and returns the store over it, with the raw handle for tests that seed or inspect rows directly. Both close when the test ends. The store seals and opens secrets with Master.

On Postgres the store runs as the app role, under row-level security, and the raw handle is the superuser, which row-level security does not apply to; it takes SQLite's ? and ?N placeholders, so seeding SQL runs on either backend.

func Postgres

func Postgres() bool

Postgres reports whether New gives tests a Postgres database.

func SQLiteOnly

func SQLiteOnly(t testing.TB, why string)

SQLiteOnly skips the test when it would run on Postgres; why says what it needs SQLite for.

Types

This section is empty.

Jump to

Keyboard shortcuts

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