test

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package test implements helpers for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllocateFreePorts

func AllocateFreePorts(n int) ([]int, error)

AllocateFreePorts finds n available ports Copied from https://github.com/tendermint/tendermint/issues/3682

func Cleanup added in v0.6.0

func Cleanup()

Cleanup removes all files and directories created by the test.

func EventuallyErr added in v0.12.0

func EventuallyErr(fn func(g gomega.Gomega), intervals ...interface{}) error

EventuallyErr runs fn repeatedly (gomega.Eventually bounded by flags.EventuallyTimeout, or the first entry of intervals if supplied, mirroring gomega.Eventually's own (timeout) / (timeout, polling) signature) and converts the result into a plain error instead of failing the enclosing Ginkgo spec. It is for plain Go helper functions that compose several fallible steps — outside any It/By closure — and need to retry a step that can transiently fail under eventual consistency (a schema-cache lag, a topology race, ...) while still returning an error their caller can wrap with step-level context.

fn receives a scoped Gomega; use it (not the package-level gomega.Expect/Ω) so a failed assertion inside fn is treated as "not yet converged" and retried, rather than aborting the whole call stack. Call gomega.StopTrying(...).Now() from within fn to end retrying immediately on a failure that must not be repeated — e.g. a partially-accepted write batch, where resending would duplicate the already-accepted rows.

func NewSpace

func NewSpace() (tempDir string, deferFunc func(), err error)

NewSpace create a tmp dir and returns the path and its clear function. It will return any error when failed to create this dir.

func SetupModules added in v0.3.0

func SetupModules(flags []string, units ...run.Unit) func()

SetupModules wires input modules to build a testing ready runtime.

func Space

func Space(t *require.Assertions) (tempDir string, deferFunc func())

Space create a tmp dir and returns the path and its clear function. It will be panic when encountering some errors.

Types

type CapturedStderr added in v0.12.0

type CapturedStderr struct {
	// contains filtered or unexported fields
}

CapturedStderr holds what the process wrote to os.Stderr while it was replaced by CaptureStderr.

func CaptureStderr added in v0.12.0

func CaptureStderr() (*CapturedStderr, error)

CaptureStderr replaces os.Stderr with a pipe and collects what is written to it. Logging reads os.Stderr when it is initialized, so a test that asserts on what a server printed calls this before it initializes logging.

The pipe is drained for the life of the process, so a writer that still holds it after Restore never blocks.

func (*CapturedStderr) Restore added in v0.12.0

func (c *CapturedStderr) Restore()

Restore puts back the os.Stderr that CaptureStderr replaced. Logging initialized during the capture keeps writing to the pipe until it is initialized again.

func (*CapturedStderr) String added in v0.12.0

func (c *CapturedStderr) String() string

String returns what has been captured so far.

func (*CapturedStderr) Write added in v0.12.0

func (c *CapturedStderr) Write(p []byte) (int, error)

Write appends p to the captured output.

type ECAssertion added in v0.11.0

type ECAssertion struct {
	// contains filtered or unexported fields
}

ECAssertion pairs a gomega Eventually with a following Consistently. It mirrors gomega.Eventually's layout: intervals may be supplied up front or via the fluent WithTimeout/WithPolling methods, and the matcher is applied via Should/ShouldNot.

func EventuallyConsistently added in v0.11.0

func EventuallyConsistently(actual interface{}, intervals ...interface{}) ECAssertion

EventuallyConsistently returns an assertion that first waits for actual to satisfy the matcher (Eventually) and then requires it to keep satisfying the matcher for a stability window (Consistently). Pairing convergence with a stability window catches transient states that briefly match and then regress, which a lone Eventually would accept.

intervals follow gomega.Eventually semantics — (timeout) or (timeout, polling). They can also be set fluently via WithTimeout/WithPolling. When the timeout is omitted it defaults to flags.EventuallyTimeout. The Consistently window always runs and reuses the polling interval, if any; its length adapts to how the Eventually phase converged — flags.QuickStabilityTimeout after a first-try success, flags.StabilityTimeout after a retried convergence (see Should).

func (ECAssertion) Should added in v0.11.0

func (a ECAssertion) Should(matcher gomegatypes.GomegaMatcher, optionalDescription ...interface{}) bool

Should asserts the matcher is reached and then held. It returns true only when both the Eventually and the Consistently assertion pass, matching the bool return of gomega's Should. optionalDescription is forwarded to both assertions.

The Consistently phase always runs, but its window is adaptive. When the Eventually phase succeeds on its very first evaluation, the state was already settled before the assertion began, so a short flags.QuickStabilityTimeout window (still a dozen re-samples) suffices to reject a one-off lucky match. Only assertions that had to retry — proof of an in-flight async process that could still regress — pay the full flags.StabilityTimeout window. This keeps the regression guard everywhere without charging every static assertion in the large query tables for a full window.

func (ECAssertion) ShouldNot added in v0.11.0

func (a ECAssertion) ShouldNot(matcher gomegatypes.GomegaMatcher, optionalDescription ...interface{}) bool

ShouldNot asserts the matcher is avoided and then kept avoided. It returns true only when both assertions pass, matching the bool return of gomega's ShouldNot. optionalDescription is forwarded to both assertions. The stability window is adaptive — see Should.

func (ECAssertion) WithPolling added in v0.11.0

func (a ECAssertion) WithPolling(polling time.Duration) ECAssertion

WithPolling overrides the polling interval used by both the Eventually and the Consistently phase, mirroring gomega.AsyncAssertion.WithPolling.

func (ECAssertion) WithTimeout added in v0.11.0

func (a ECAssertion) WithTimeout(timeout time.Duration) ECAssertion

WithTimeout overrides the Eventually convergence timeout, mirroring gomega.AsyncAssertion.WithTimeout.

type NativeLines added in v0.12.0

type NativeLines struct {
	// contains filtered or unexported fields
}

NativeLines is a native sink that keeps every line native storage would receive.

func NativeLoggingAtWarn added in v0.12.0

func NativeLoggingAtWarn(t testing.TB) *NativeLines

NativeLoggingAtWarn turns native logging on at warn and returns the sink that receives what is stored natively. Logging is initialized again when the test ends, so later tests do not inherit native logging.

func (*NativeLines) Admit added in v0.12.0

func (n *NativeLines) Admit(_ zerolog.Level, _ string, line []byte)

Admit keeps line.

func (*NativeLines) Count added in v0.12.0

func (n *NativeLines) Count() int

Count returns how many lines were kept.

Directories

Path Synopsis
Package flags implements injected flags to run tests.
Package flags implements injected flags to run tests.
Package flow implements mockers for testing flow.
Package flow implements mockers for testing flow.
Package gmatcher provides custom Gomega matchers.
Package gmatcher provides custom Gomega matchers.
Package helpers implements several helpers for testing.
Package helpers implements several helpers for testing.
Package leakcheck fails a test binary that finishes with resources still held.
Package leakcheck fails a test binary that finishes with resources still held.
Package measure implements helpers to load schemas for testing.
Package measure implements helpers to load schemas for testing.
Package property implements helpers to load schemas for testing.
Package property implements helpers to load schemas for testing.
Package query provides functions for analyzing and collecting metrics.
Package query provides functions for analyzing and collecting metrics.
replicated
measure
Package replicatedmeasure implements helpers to load replicated schemas for testing.
Package replicatedmeasure implements helpers to load replicated schemas for testing.
stream
Package replicatedstream implements helpers to load replicated schemas for testing.
Package replicatedstream implements helpers to load replicated schemas for testing.
trace
Package trace implements helpers to load replicated schemas for testing.
Package trace implements helpers to load replicated schemas for testing.
Package setup implements a real env in which to run tests.
Package setup implements a real env in which to run tests.
Package stream implements helpers to load schemas for testing.
Package stream implements helpers to load schemas for testing.
Package trace implements helpers to load schemas for testing.
Package trace implements helpers to load schemas for testing.
Package transfer holds helpers the data-export integration suites share.
Package transfer holds helpers the data-export integration suites share.
progress
Package progress counts what the tests assert on in the progress files of a data export and a data import, read the way the exporter and the importer read them.
Package progress counts what the tests assert on in the progress files of a data export and a data import, read the way the exporter and the importer read them.
topncheck
Package topncheck asserts the Top-N results of a CSV export.
Package topncheck asserts the Top-N results of a CSV export.

Jump to

Keyboard shortcuts

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