Documentation
¶
Overview ¶
Package testutil provides common test utilities for the Ofelia project.
Index ¶
- Constants
- func Eventually(t testing.TB, condition func() bool, opts ...Option) bool
- func EventuallyWithT(t testing.TB, condition func(collect *T) bool, opts ...Option) bool
- func Never(t testing.TB, condition func() bool, opts ...Option) bool
- func WaitForChan[T any](t testing.TB, ch <-chan T, timeout time.Duration) (T, bool)
- func WaitForClose[T any](t testing.TB, ch <-chan T, timeout time.Duration) bool
- type Option
- type T
Constants ¶
const DefaultInterval = 50 * time.Millisecond
DefaultInterval is the default polling interval for Eventually.
const DefaultTimeout = 5 * time.Second
DefaultTimeout is the default timeout for Eventually.
Variables ¶
This section is empty.
Functions ¶
func Eventually ¶
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 ¶
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 ¶
Never is the inverse of Eventually - it asserts that a condition never becomes true within the timeout period.
func WaitForChan ¶
WaitForChan waits for a channel to receive a value or closes within the timeout. Returns true if the channel received/closed, false on timeout.
Types ¶
type Option ¶
type Option func(*config)
Option configures Eventually behavior.
func WithInterval ¶
WithInterval sets the polling interval.
func WithMessage ¶
WithMessage sets the error message shown on timeout.
func WithTimeout ¶
WithTimeout sets the maximum time to wait for the condition.