erltest

package
v0.16.0-rc.8 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

this package contains the TestReceiver which is a process that can have message expectations set on them. These expectations match messages sent to the process inbox and execute a [TestExpectation] function. The function returns true to pass and false to fail the test.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultReceiverTimeout time.Duration = chronos.Dur("10s")
	DefaultWaitTimeout     time.Duration = chronos.Dur("5s")
)

Functions

This section is empty.

Types

type BoolTestCallExpectation added in v0.16.1

type BoolTestCallExpectation func(self erl.PID, from genserver.From, msg any) bool

type BoolTestExpectation added in v0.16.1

type BoolTestExpectation func(self erl.PID, msg any) bool

type ExpectArg added in v0.16.1

type ExpectArg struct {
	// The term that was matched against. A simple type in the case of [reflect.Type], or
	// possibly a string, number, etc.
	Match any
	Msg   any
	// This is only populated for Calls
	From     *genserver.From
	Self     erl.PID
	MsgCount int
	Exp      Expectation
}

type Expectation added in v0.16.1

type Expectation interface {
	Check(arg ExpectArg) (Expectation, *ExpectationFailure)
	Satisfied(testDone bool) bool
	// unique identifier, to simplify nested Expectation registration with the [TestReceiver]
	ID() string
	Name() string
}

type ExpectationFailure

type ExpectationFailure struct {
	// The matching term that led to the ExpectationFailure
	Match any
	// The failed expectation
	Exp Expectation
	// The actual message that matched [Match] and was evaluated by the Expectation
	Msg any
	// Failure message
	Reason string
}

func Fail added in v0.16.1

func Fail(ea ExpectArg, reason string) *ExpectationFailure

func (*ExpectationFailure) String added in v0.16.1

func (ef *ExpectationFailure) String() string

type ReceiverOpt added in v0.16.1

type ReceiverOpt func(ro receiverOptions) receiverOptions

func NoFail added in v0.16.1

func NoFail() ReceiverOpt

Set this if you do not want the TestReceiver to call testing.T.Fail in the [Wait] method.

func ReceiverTimeout added in v0.16.1

func ReceiverTimeout(t time.Duration) ReceiverOpt

Specify how long the test reciever should run for before stopping. this needs to be set otherwise tests will hang until exceptions are matched or the 10min Go default is reached. See DefaultReceiverTimeout

func WaitTimeout added in v0.16.1

func WaitTimeout(t time.Duration) ReceiverOpt

Specify how long for [TestReciever.Wait] for all expectations to be met see DefaultWaitTimeout

type TestReceiver

type TestReceiver struct {
	// contains filtered or unexported fields
}

func NewReceiver

func NewReceiver(t *testing.T, opts ...ReceiverOpt) (erl.PID, *TestReceiver)

Creates a new TestReceiver, which is a process that you can set message matching expectations on.

func (*TestReceiver) Expect

func (tr *TestReceiver) Expect(matchTerm any, e Expectation)

Set an expectation that will be matched whenever a [matchTerm] msg type is received.

func (*TestReceiver) ExpectCall added in v0.15.0

func (tr *TestReceiver) ExpectCall(matchTerm any, e Expectation)

This is like [Expect] but is only tested against genserver.CallRequest messages. NOTE: You should use genserver.Reply to send a response to the genserver.From, otherwise the caller will timeout

func (*TestReceiver) ExpectCast added in v0.15.0

func (tr *TestReceiver) ExpectCast(matchTerm any, e Expectation)

This is like [Expect] but is only tested against genserver.CastRequest messages.

func (*TestReceiver) Failures added in v0.16.1

func (tr *TestReceiver) Failures() []*ExpectationFailure

func (*TestReceiver) Pass

func (tr *TestReceiver) Pass() (int, bool)

returns the number of failed expectations and whether all expectations have been satisifed. An expectation is not satisfied unless it is invoked in the correct time and order

func (*TestReceiver) Receive

func (tr *TestReceiver) Receive(self erl.PID, inbox <-chan any) error

func (*TestReceiver) Stop added in v0.15.0

func (tr *TestReceiver) Stop(self erl.PID)

will cause the test receiver to exit, sending signals to linked and monitoring processes. This is not needed for normal test cleanup (that is handled via [t.Cleanup()])

func (*TestReceiver) T added in v0.16.1

func (tr *TestReceiver) T() *testing.T

return the *testing.T. Don't use this in situations that could run after a test is failed, the race detector doesn't like that.

func (*TestReceiver) Wait

func (tr *TestReceiver) Wait()

Returns when the WaitTimeout expires or an expectation fails. If at the end of the timeout not all expectations are satisifed, the test is failed. Call this after you have sent your messages and want fail if your expecations don't pass

func (*TestReceiver) WaitOn added in v0.16.1

func (tr *TestReceiver) WaitOn(e ...Expectation)

Register an expectation wit this TestReciever. It will be checked when Pass is called (and as a consequnce, cause [Wait] to block until its success)

Directories

Path Synopsis
* This package provides "assertions" for use in [erltest.TestExpectation]s.
* This package provides "assertions" for use in [erltest.TestExpectation]s.

Jump to

Keyboard shortcuts

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