testutil

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package testutil provides testing helpers.

Index

Constants

This section is empty.

Variables

View Source
var (
	// RootDir is the FerretDB <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
	// TmpRecordsDir is the <root>/tmp/records directory.
	TmpRecordsDir string
)

Functions

func AssertEqual added in v0.1.0

func AssertEqual[T types.Type](tb testtb.TB, expected, actual T) bool

AssertEqual asserts that two BSON values are equal.

func AssertEqualSlices added in v0.5.1

func AssertEqualSlices[T types.Type](tb testtb.TB, expected, actual []T) bool

AssertEqualSlices asserts that two BSON slices are equal.

func AssertNotEqual added in v0.1.0

func AssertNotEqual[T types.Type](tb testtb.TB, expected, actual T) bool

AssertNotEqual asserts that two BSON values are not equal.

func AssertNotEqualSlices added in v0.5.1

func AssertNotEqualSlices[T types.Type](tb testtb.TB, expected, actual []T) bool

AssertNotEqualSlices asserts that two BSON slices are not equal.

func CollectionName added in v0.5.1

func CollectionName(tb testtb.TB) string

CollectionName returns a stable FerretDB collection name for that test.

func CompareAndSetByPathNum added in v0.0.5

func CompareAndSetByPathNum[T types.CompositeTypeInterface](tb testtb.TB, expected, actual T, delta float64, path types.Path)

CompareAndSetByPathNum asserts that two values with the same path in two objects (documents or arrays) are within a given numerical delta, then updates the expected object with the actual value.

func CompareAndSetByPathTime added in v0.0.5

func CompareAndSetByPathTime[T types.CompositeTypeInterface](tb testtb.TB, expected, actual T, delta time.Duration, path types.Path)

CompareAndSetByPathTime asserts that two values with the same path in two objects (documents or arrays) are within a given time delta, then updates the expected object with the actual value.

func Ctx

func Ctx(tb testtb.TB) context.Context

Ctx returns test context. It is canceled when test is finished or interrupted.

func DatabaseName added in v0.5.1

func DatabaseName(tb testtb.TB) string

DatabaseName returns a stable FerretDB database name for that test.

func DirectoryName added in v1.13.0

func DirectoryName(tb testtb.TB) string

DirectoryName returns a stable directory name for that test.

It also could be used as PostgreSQL database name (not FerretDB database / PostgreSQL schema name).

func GetByPath added in v0.0.5

func GetByPath[T types.CompositeTypeInterface](tb testtb.TB, comp T, path types.Path) any

GetByPath returns a value by path - a sequence of indexes and keys.

func IndentJSON added in v0.4.0

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

IndentJSON returns an indented form of the JSON input.

func LevelLogger added in v1.4.0

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

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

func Logger added in v0.6.0

func Logger(tb testtb.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 SetByPath added in v0.0.5

func SetByPath[T types.CompositeTypeInterface](tb testtb.TB, comp T, value any, path types.Path)

SetByPath sets the value by path - a sequence of indexes and keys.

The path must exist.

func TestHanaURI added in v1.18.0

func TestHanaURI(tb testtb.TB) string

TestHanaURI returns a HANA Database URL for testing. HANATODO Create a Database per test run?

func TestMySQLURI added in v1.16.0

func TestMySQLURI(tb testtb.TB, ctx context.Context, baseURI string) string

TestMySQLURI returns MySQL URI with test-specific database. It will be created before test and dropped after unless test fails.

Base URI may be empty.

func TestPostgreSQLURI added in v1.15.0

func TestPostgreSQLURI(tb testtb.TB, ctx context.Context, baseURI string) string

TestPostgreSQLURI returns PostgreSQL URI with test-specific database. It will be created before test and dropped after unless test fails.

Base URI may be empty.

func TestSQLiteURI added in v1.15.0

func TestSQLiteURI(tb testtb.TB, baseURI string) string

TestSQLiteURI returns SQLite URI with test-specific directory. It will be created before test and dropped after unless test fails.

Base URI may be empty.

func Unindent added in v1.21.0

func Unindent(tb testtb.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 testfail provides testing helpers for expected tests failures.
Package testfail provides testing helpers for expected tests failures.
Package teststress provides a helper for stress testing.
Package teststress provides a helper for stress testing.
Package testtb provides a common testing interface.
Package testtb provides a common testing interface.

Jump to

Keyboard shortcuts

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