testkit

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 13 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 Option added in v2.8.0

type Option interface {
	// Apply sets the Option value of a config.
	Apply(kit *TestKit)
}

Option is the interface that applies a Testkit option.

func WithLogging added in v2.8.0

func WithLogging(level log.Level) Option

WithLogging sets the Testkit logger

type OptionFunc added in v2.8.0

type OptionFunc func(kit *TestKit)

OptionFunc implements the Option interface.

func (OptionFunc) Apply added in v2.8.0

func (f OptionFunc) Apply(kit *TestKit)

type Probe

type Probe interface {
	// ExpectMessage asserts that the message received from the test actor is the expected one
	ExpectMessage(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)
	// 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 the actor to be tested.
	// This method is only used when one to assert that the actor to be tested is able to respond when a Tell message is sent.
	Send(actorName string, message proto.Message)
	// SendSync sends a message to the actor to be tested and expect a response within a time duration.
	// This method is only used when one to assert that the actor to be tested is able to respond when an Ask message is sent.
	SendSync(actorName string, message proto.Message, timeout time.Duration)
	// 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, opts ...Option) *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)

Spawn create an actor

Jump to

Keyboard shortcuts

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