testutil

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package testutil provides common test utilities for the Ofelia project.

Index

Constants

View Source
const DefaultInterval = 50 * time.Millisecond

DefaultInterval is the default polling interval for Eventually.

View Source
const DefaultTimeout = 5 * time.Second

DefaultTimeout is the default timeout for Eventually.

Variables

This section is empty.

Functions

func Eventually

func Eventually(t testing.TB, condition func() bool, opts ...Option) bool

Eventually polls a condition function until it returns true or the timeout expires. This replaces time.Sleep-based synchronization with event-driven waiting.

Example:

testutil.Eventually(t, func() bool {
    return server.IsReady()
}, testutil.WithTimeout(2*time.Second))

func EventuallyWithT

func EventuallyWithT(t testing.TB, condition func(collect *T) bool, opts ...Option) bool

EventuallyWithT is like Eventually but passes a *testing.T to the condition. This allows the condition to make assertions that won't fail the test until the timeout is reached.

func Never

func Never(t testing.TB, condition func() bool, opts ...Option) bool

Never is the inverse of Eventually - it asserts that a condition never becomes true within the timeout period.

func WaitForChan

func WaitForChan[T any](t testing.TB, ch <-chan T, timeout time.Duration) (T, bool)

WaitForChan waits for a channel to receive a value or closes within the timeout. Returns true if the channel received/closed, false on timeout.

func WaitForClose

func WaitForClose[T any](t testing.TB, ch <-chan T, timeout time.Duration) bool

WaitForClose waits for a channel to close within the timeout.

Types

type Option

type Option func(*config)

Option configures Eventually behavior.

func WithInterval

func WithInterval(d time.Duration) Option

WithInterval sets the polling interval.

func WithMessage

func WithMessage(msg string) Option

WithMessage sets the error message shown on timeout.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the maximum time to wait for the condition.

type T

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

T is a collector for errors during EventuallyWithT.

func (*T) Errorf

func (t *T) Errorf(format string, args ...any)

Errorf records an error (does not fail immediately).

func (*T) Failed

func (t *T) Failed() bool

Failed returns true if any errors were recorded.

Jump to

Keyboard shortcuts

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