Documentation
¶
Overview ¶
Package arrangetest contains useful unit test utilities for working with dependency injection and client/server lifecycle.
Index ¶
- func ListenCapture(ch chan<- net.Addr) func(net.Listener) net.Listener
- func ListenReceive(v any, ch <-chan net.Addr, timeout time.Duration) (addr net.Addr)
- func NewApp(t any, o ...fx.Option) *fxtest.App
- func NewErrApp(t any, o ...fx.Option) *fx.App
- type MockAddr
- type MockListener
- func (m *MockListener) Accept() (net.Conn, error)
- func (m *MockListener) Addr() net.Addr
- func (m *MockListener) Close() error
- func (m *MockListener) ExpectAccept(c net.Conn, err error) *mock.Call
- func (m *MockListener) ExpectAddr(a net.Addr) *mock.Call
- func (m *MockListener) ExpectClose(err error) *mock.Call
- type Testable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenCapture ¶ added in v0.5.0
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
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
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
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
MockAddr is a mocked net.Addr.
func (*MockAddr) ExpectNetwork ¶ added in v0.5.0
func (*MockAddr) ExpectString ¶ added in v0.5.0
type MockListener ¶ added in v0.5.0
MockListener is a mocked net.Listener.
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 (*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
Testable is the minimal interface required for assertions and testing. This interface is implemented by several libraries.
func AsTestable ¶ added in v0.5.0
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.