Documentation ¶
Overview ¶
Package fxtest provides utilities for testing Fx modules, and code that directly uses Fx.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTestLogger ¶ added in v1.14.0
NewTestLogger returns an fxlog.Logger that logs to the testing TB.
func NewTestPrinter ¶ added in v1.7.1
NewTestPrinter returns a fx.Printer that logs to the testing TB.
func WithTestLogger ¶ added in v1.21.0
WithTestLogger returns an fx.Option that uses the provided TB as the destination for Fx's log output.
Types ¶
type App ¶
App is a wrapper around fx.App that provides some testing helpers. By default, it uses the provided TB as the application's logging backend.
func (*App) RequireStart ¶
RequireStart calls Start, failing the test if an error is encountered.
func (*App) RequireStop ¶
func (app *App) RequireStop()
RequireStop calls Stop, failing the test if an error is encountered.
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
Lifecycle is a testing spy for fx.Lifecycle. It exposes Start and Stop methods (and some test-specific helpers) so that unit tests can exercise hooks.
func NewLifecycle ¶
func NewLifecycle(t TB, opts ...LifecycleOption) *Lifecycle
NewLifecycle creates a new test lifecycle.
func (*Lifecycle) RequireStart ¶
RequireStart calls Start with context.Background(), failing the test if an error is encountered.
func (*Lifecycle) RequireStop ¶
func (l *Lifecycle) RequireStop()
RequireStop calls Stop with context.Background(), failing the test if an error is encountered.
func (*Lifecycle) Start ¶
Start executes all registered OnStart hooks in order, halting at the first hook that doesn't succeed.
type LifecycleOption ¶ added in v1.22.0
type LifecycleOption interface {
// contains filtered or unexported methods
}
LifecycleOption modifies the behavior of the Lifecycle when passed to NewLifecycle.
func EnforceTimeout ¶ added in v1.22.0
func EnforceTimeout(enforce bool) LifecycleOption
EnforceTimeout will cause the Lifecycle's Start and Stop methods to return an error as soon as context expires, regardless of whether specific hooks respect the timeout.