fxtest

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

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

New creates a new test application.

func (*App) RequireStart

func (app *App) RequireStart() *App

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) *Lifecycle

NewLifecycle creates a new test lifecycle.

func (*Lifecycle) Append

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

Append registers a new Hook.

func (*Lifecycle) RequireStart

func (l *Lifecycle) RequireStart() *Lifecycle

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

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

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

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.

Jump to

Keyboard shortcuts

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