erltest

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 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

This section is empty.

Functions

This section is empty.

Types

type ExpectOpt

type ExpectOpt func(o expectOpts) expectOpts

func Absolute

func Absolute(nthMsg int) ExpectOpt

specify that an expectation should match the Nth msg received by the TestReceiver

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

func AtLeast

func AtLeast(n int) ExpectOpt

expectation will pass only if matched >=[n] times.

func AtMost

func AtMost(n int) ExpectOpt

Expectation is satisifed if it is executed up to [n] times. Zero executions will also pass, so ensure that you are sleeping the test or have other expectations so [TestReciever.Wait] does not exit immediately

func Times

func Times(n int) ExpectOpt

Expectation is satisifed only if it is invoed [n] times.

type ExpectationFailure

type ExpectationFailure struct {
	MatchType reflect.Type
	Msg       any
	Reason    string
}

type TestCallExpectation added in v0.15.0

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

type TestExpectation

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

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

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