fx: go.uber.org/fx/fxtest Index | Files

package fxtest

import "go.uber.org/fx/fxtest"

Index

Package Files

fxtest.go printer.go

func NewTestPrinter Uses

func NewTestPrinter(t TB) fx.Printer

NewTestPrinter returns a fx.Printer that logs to the testing TB.

type App Uses

type App struct {
    *fx.App
    // contains filtered or unexported fields
}

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 New Uses

func New(tb TB, opts ...fx.Option) *App

New creates a new test application.

func (*App) RequireStart Uses

func (app *App) RequireStart() *App

RequireStart calls Start, failing the test if an error is encountered.

func (*App) RequireStop Uses

func (app *App) RequireStop()

RequireStop calls Stop, failing the test if an error is encountered.

type Lifecycle Uses

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 Uses

func NewLifecycle(t TB) *Lifecycle

NewLifecycle creates a new test lifecycle.

func (*Lifecycle) Append Uses

func (l *Lifecycle) Append(h fx.Hook)

Append registers a new Hook.

func (*Lifecycle) RequireStart Uses

func (l *Lifecycle) RequireStart() *Lifecycle

RequireStart calls Start with context.Background(), failing the test if an error is encountered.

func (*Lifecycle) RequireStop Uses

func (l *Lifecycle) RequireStop()

RequireStop calls Stop with context.Background(), failing the test if an error is encountered.

func (*Lifecycle) Start Uses

func (l *Lifecycle) Start(ctx context.Context) error

Start executes all registered OnStart hooks in order, halting at the first hook that doesn't succeed.

func (*Lifecycle) Stop Uses

func (l *Lifecycle) Stop(ctx context.Context) error

Stop calls all OnStop hooks whose OnStart counterpart was called, running in reverse order.

If any hook returns an error, execution continues for a best-effort cleanup. Any errors encountered are collected into a single error and returned.

type TB Uses

type TB interface {
    Logf(string, ...interface{})
    Errorf(string, ...interface{})
    FailNow()
}

TB is a subset of the standard library's testing.TB interface. It's satisfied by both *testing.T and *testing.B.

Package fxtest imports 3 packages (graph) and is imported by 1 packages. Updated 2019-07-11. Refresh now. Tools for package owners.