testkit

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessagesQueueMax int           = 1000
	DefaultTimeout   time.Duration = 3 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Probe

type Probe interface {
	// ExpectMessage asserts that the message received from the test actor is the expected one
	ExpectMessage(message proto.Message) proto.Message
	// ExpectMessageWithin asserts that the message received from the test actor is the expected one within a time duration
	ExpectMessageWithin(duration time.Duration, message proto.Message) proto.Message
	// ExpectNoMessage asserts that no message is expected
	ExpectNoMessage()
	// ExpectAnyMessage asserts that any message is expected
	ExpectAnyMessage() proto.Message
	// ExpectAnyMessageWithin asserts that any message within a time duration
	ExpectAnyMessageWithin(duration time.Duration) proto.Message
	// ExpectMessageOfType asserts the expectation of a given message type
	ExpectMessageOfType(messageType protoreflect.MessageType)
	// ExpectMessageOfTypeWithin asserts the expectation of a given message type within a time duration
	ExpectMessageOfTypeWithin(duration time.Duration, messageType protoreflect.MessageType)
	// Send sends a message to an actor and also provides probe's test actor PID as sender.
	Send(to actors.PID, message proto.Message)
	// Sender returns the sender of last received message.
	Sender() actors.PID
	// PID returns the pid of the test actor
	PID() actors.PID
	// Stop stops the test probe
	Stop()
}

Probe defines the probe interface that helps perform some assertions when implementing unit tests with actors

type TestKit

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

TestKit defines actor test kit

func New

func New(ctx context.Context, t *testing.T) *TestKit

New creates an instance of TestKit

func (*TestKit) NewProbe

func (k *TestKit) NewProbe(ctx context.Context) Probe

NewProbe create a test probe

func (*TestKit) Shutdown

func (k *TestKit) Shutdown(ctx context.Context)

Shutdown stops the test kit

func (*TestKit) Spawn

func (k *TestKit) Spawn(ctx context.Context, name string, actor actors.Actor) actors.PID

Spawn create an actor

Jump to

Keyboard shortcuts

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