Documentation
¶
Index ¶
- Variables
- func BaseServiceArchetype(tb testing.TB) *baseservice.Archetype
- func DBPool(ctx context.Context, tb testing.TB) *pgxpool.Pool
- func DBPoolClone(ctx context.Context, tb testing.TB) *pgxpool.Pool
- func DBPoolLibSQL(ctx context.Context, tb testing.TB, schema string) *sql.DB
- func DBPoolSQLite(ctx context.Context, tb testing.TB, schema string) *sql.DB
- func Logger(tb testing.TB) *slog.Logger
- func LoggerWarn(tb testutil.TestingTB) *slog.Logger
- func TestDatabaseURL() string
- func WaitOrTimeout[T any](tb testing.TB, waitChan <-chan T) T
- func WaitOrTimeoutN[T any](tb testutil.TestingTB, waitChan <-chan T, numValues int) []T
- func WaitTimeout() time.Duration
- func WrapTestMain(m *testing.M)
- type TimeStub
Constants ¶
This section is empty.
Variables ¶
var IgnoredKnownGoroutineLeaks = []goleak.Option{ goleak.IgnoreTopFunction("github.com/jackc/pgx/v5/pgxpool.(*Pool).backgroundHealthCheck"), goleak.IgnoreAnyFunction("github.com/jackc/pgx/v5/pgxpool.(*Pool).triggerHealthCheck.func1"), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"), }
Functions ¶
func BaseServiceArchetype ¶
func BaseServiceArchetype(tb testing.TB) *baseservice.Archetype
BaseServiceArchetype returns a new base service suitable for use in tests. Returns a new instance so that it's not possible to accidentally taint a shared object.
func DBPool ¶ added in v0.20.0
DBPool gets a lazily initialized database pool for `TEST_DATABASE_URL` or `river_test` if the former isn't specified.
func DBPoolClone ¶ added in v0.21.0
DBPoolClone returns a disposable clone of DBPool. Share resources by using DBPool when possible, but this is useless for areas like stress tests where context cancellations are likely to end up closing the pool.
Unlike DBPool, adds a test cleanup hook that closes the pool after run.
func DBPoolLibSQL ¶ added in v0.24.0
DBPoolLibSQL gets a database pool appropriate for use with libSQL (a SQLite fork) in testing.
func DBPoolSQLite ¶ added in v0.23.0
DBPoolSQLite gets a database pool appropriate for use with SQLite in testing.
func Logger ¶
Logger returns a logger suitable for use in tests.
Defaults to informational verbosity. If env is set with `RIVER_DEBUG=true`, debug level verbosity is activated.
func LoggerWarn ¶
LoggerWarn returns a logger suitable for use in tests which outputs only at warn or above. Useful in tests where particularly noisy log output is expected.
func TestDatabaseURL ¶ added in v0.21.0
func TestDatabaseURL() string
TestDatabaseURL returns `TEST_DATABASE_URL` or a default URL pointing to `river_test` and with suitable connection configuration defaults.
func WaitOrTimeout ¶
WaitOrTimeout tries to wait on the given channel for a value to come through, and returns it if one does, but times out after a reasonable amount of time. Useful to guarantee that test cases don't hang forever, even in the event of something wrong.
func WaitOrTimeoutN ¶
WaitOrTimeoutN tries to wait on the given channel for N values to come through, and returns it if they do, but times out after a reasonable amount of time. Useful to guarantee that test cases don't hang forever, even in the event of something wrong.
func WaitTimeout ¶
WaitTimeout returns a duration broadly appropriate for waiting on an expected event in a test, and which is used for `TestSignal.WaitOrTimeout` in the main package and `WaitOrTimeout` above. Its main purpose is to allow a little extra leeway in GitHub Actions where we occasionally seem to observe subpar performance which leads to timeouts and test intermittency, while still keeping a tight a timeout for local test runs where this is never a problem.
func WrapTestMain ¶
WrapTestMain performs some common setup and teardown that should be shared amongst all packages. e.g. Configures a manager for test databases on setup, and checks for no goroutine leaks on teardown.
Types ¶
type TimeStub ¶
type TimeStub struct {
// contains filtered or unexported fields
}
TimeStub implements baseservice.TimeGeneratorWithStub to allow time to be stubbed in tests.
It exists separately from rivertest.TimeStub to avoid a circular dependency.