testutil

package
v1.24.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package testutil provides testing helpers.

Index

Constants

This section is empty.

Variables

View Source
var (
	// RootDir is the DocDB <root> directory.
	RootDir string

	// BinDir is the <root>/bin directory.
	BinDir string

	// BuildCertsDir is the <root>/build/certs directory.
	BuildCertsDir string

	// IntegrationDir is the <root>/integration directory.
	IntegrationDir string

	// TmpDir is the <root>/tmp directory.
	TmpDir string

	// TmpRecordsDir is the <root>/tmp/records directory.
	TmpRecordsDir string
)

Functions

func AssertEqual deprecated

func AssertEqual[T wirebson.Type](tb testing.TB, expected, actual T) bool

AssertEqual asserts that two BSON values are equal.

Deprecated: use wiretest.AssertEqual instead.

func CollectionName

func CollectionName(tb testing.TB) string

CollectionName returns a stable DocDB collection name for that test.

func Ctx

func Ctx(tb testing.TB) context.Context

Ctx returns test context with OpenTelemetry span, that also can be used with Exclusive. It is canceled when test is finished or interrupted.

Integration tests should use this function. Many unit tests could use the standard testing.T.Context instead.

func DatabaseName

func DatabaseName(tb testing.TB) string

DatabaseName returns a stable DocDB database name for that test.

func Exclusive

func Exclusive(ctx context.Context, reason string)

Exclusive signals that test calling that function can't be run in parallel with any other test that uses Ctx to get test context, including tests in other packages.

The bar for using this helper is very high. Most tests can run in parallel with other tests just fine by retrying operations, filtering results, or using different instances of system under test (collections, databases, etc).

func IndentJSON

func IndentJSON(tb testing.TB, b []byte) []byte

IndentJSON returns an indented form of the JSON input.

func LevelLogger

func LevelLogger(tb testing.TB, level slog.Leveler) *slog.Logger

LevelLogger returns a slog test logger for the given level (which might be dynamic).

func Logger

func Logger(tb testing.TB) *slog.Logger

Logger returns slog test logger.

func MustParseDumpFile

func MustParseDumpFile(path ...string) []byte

MustParseDumpFile panics if fails to parse file input to byte array.

func PostgreSQLURL

func PostgreSQLURL(tb testing.TB) string

PostgreSQLURL returns PostgreSQL URL for testing.

It skips the test if it is in short mode.

func Unindent

func Unindent(tb testing.TB, s string) string

Unindent removes the common number of leading tabs from all lines in s.

Types

This section is empty.

Directories

Path Synopsis
Package teststress provides a helper for stress testing.
Package teststress provides a helper for stress testing.

Jump to

Keyboard shortcuts

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