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 ¶
- type ExpectOpt
- type ExpectationFailure
- type TestCallExpectation
- type TestExpectation
- type TestReceiver
- func (tr *TestReceiver) Expect(expected any, handler TestExpectation, opts ...ExpectOpt)
- func (tr *TestReceiver) ExpectCall(expected any, handler TestCallExpectation, opts ...ExpectOpt)
- func (tr *TestReceiver) ExpectCast(expected any, handler TestExpectation, opts ...ExpectOpt)
- func (tr *TestReceiver) Pass() (int, bool)
- func (tr *TestReceiver) Receive(self erl.PID, inbox <-chan any) error
- func (tr *TestReceiver) Stop(self erl.PID)
- func (tr *TestReceiver) Wait()
- func (tr *TestReceiver) WaitFor(tout time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpectOpt ¶
type ExpectOpt func(o expectOpts) expectOpts
func AnyTimes ¶
func AnyTimes() ExpectOpt
Expectation is satisifed if it is executed zero or more times. Ensure that you are sleeping the test or have other expectations so [TestReciever.Wait] does not exit immediately
type ExpectationFailure ¶
type TestCallExpectation ¶ added in v0.15.0
type TestReceiver ¶
type TestReceiver struct {
// contains filtered or unexported fields
}
func NewReceiver ¶
func NewReceiver(t *testing.T) (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(expected any, handler TestExpectation, opts ...ExpectOpt)
Set an expectation that will be matched whenever an [expected] msg type is received.
func (*TestReceiver) ExpectCall ¶ added in v0.15.0
func (tr *TestReceiver) ExpectCall(expected any, handler TestCallExpectation, opts ...ExpectOpt)
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(expected any, handler TestExpectation, opts ...ExpectOpt)
This is like [Expect] but is only tested against genserver.CastRequest messages.
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) Wait ¶
func (tr *TestReceiver) Wait()
same as [WaitFor], but uses default test timeout
func (*TestReceiver) WaitFor ¶
func (tr *TestReceiver) WaitFor(tout time.Duration)
Returns when the [tout] 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