arrangetest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package arrangetest contains useful unit test utilities for working with dependency injection and client/server lifecycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenCapture added in v0.5.0

func ListenCapture(ch chan<- net.Addr) func(net.Listener) net.Listener

ListenCapture returns a middleware that captures the bind address for a net.Listener. The given channel receives net.Listener.Addr(), but the returned middleware does not decorate the listener at all.

A typical use case is using ListenCapture as an external ListenerMiddleware during tests to capture the actual bind address for a test server, which will typically have an Addr of ":0".

func ListenReceive added in v0.5.0

func ListenReceive(v any, ch <-chan net.Addr, timeout time.Duration) (addr net.Addr)

ListenReceive returns the first net.Addr received on a channel, typically previously passed to ListenCapture. If timeout elapses, the enclosing test is failed.

The v parameter must be convertible via AsTestable, or this function panics.

func NewApp added in v0.5.0

func NewApp(t any, o ...fx.Option) *fxtest.App

NewApp creates an *fxtest.App using the enclosing test.

The t parameter may supply a T() *testing.T method, as in the case of a stretchr test suite. Or, it may implement fxtest.TB directly, as is the case with *testing.T and *testing.B.

func NewErrApp added in v0.5.0

func NewErrApp(t any, o ...fx.Option) *fx.App

NewErrApp creates an *fx.App which is expected to fail during construction. Prior to returning, this function asserts that there was an error. The *fx.App is returned for any further assertions. The t parameter has the same restrictions as NewApp.

Since an error is assumed to happen, the returned app has logging silenced.

Types

type MockAddr added in v0.5.0

type MockAddr struct {
	mock.Mock
}

MockAddr is a mocked net.Addr.

func (*MockAddr) ExpectNetwork added in v0.5.0

func (m *MockAddr) ExpectNetwork(n string) *mock.Call

func (*MockAddr) ExpectString added in v0.5.0

func (m *MockAddr) ExpectString(n string) *mock.Call

func (*MockAddr) Network added in v0.5.0

func (m *MockAddr) Network() string

func (*MockAddr) String added in v0.5.0

func (m *MockAddr) String() string

type MockListener added in v0.5.0

type MockListener struct {
	mock.Mock
}

MockListener is a mocked net.Listener.

func (*MockListener) Accept added in v0.5.0

func (m *MockListener) Accept() (net.Conn, error)

func (*MockListener) Addr added in v0.5.0

func (m *MockListener) Addr() net.Addr

func (*MockListener) Close added in v0.5.0

func (m *MockListener) Close() error

func (*MockListener) ExpectAccept added in v0.5.0

func (m *MockListener) ExpectAccept(c net.Conn, err error) *mock.Call

func (*MockListener) ExpectAddr added in v0.5.0

func (m *MockListener) ExpectAddr(a net.Addr) *mock.Call

func (*MockListener) ExpectClose added in v0.5.0

func (m *MockListener) ExpectClose(err error) *mock.Call

type Testable added in v0.5.0

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

Testable is the minimal interface required for assertions and testing. This interface is implemented by several libraries.

func AsTestable added in v0.5.0

func AsTestable(v any) Testable

AsTestable converts a value into a Testable. The v parameter may be a *testing.T, *testing.B, or a type that provides a T() *testing.T method.

If v cannot be coerced into a Testable, this function panics.

Jump to

Keyboard shortcuts

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