testkit

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 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 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, 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) *actors.PID

Spawn create an actor

Jump to

Keyboard shortcuts

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