Documentation
¶
Overview ¶
Package pastrytest provides various helpers for testing Pastry networks.
Index ¶
- func Check(t *testing.T, f func(t *rapid.T, logger *slog.Logger))
- func DistinctIdentifiers(minSize, maxSize int) *rapid.Generator[[]pastry.Identifier]
- func MessageOfType[M pastry.Message](callback func(dest pastry.Node, msg M)) func(SentMessage)
- func NewLogger(w io.Writer) *slog.Logger
- func NilSliceOf[T any](element *rapid.Generator[T]) *rapid.Generator[[]T]
- func RandomIdentifier() *rapid.Generator[pastry.Identifier]
- func RandomProximity() *rapid.Generator[pastry.Proximity]
- func RoutedMessageOfType[M pastry.Message](...) func(SentMessage)
- func WithLogger(t *testing.T, f func(t *testing.T, logger *slog.Logger))
- type SentMessage
- type SentMessages
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check runs a Rapid property test while collecting any log and slog output that it produces. If the test fails, we will display the collected log output of the final failing test instance.
func DistinctIdentifiers ¶
func DistinctIdentifiers(minSize, maxSize int) *rapid.Generator[[]pastry.Identifier]
DistinctIdentifiers returns a property test generator that produces a list of identifiers that are guaranteed to be unique.
func MessageOfType ¶
func MessageOfType[M pastry.Message](callback func(dest pastry.Node, msg M)) func(SentMessage)
MessageOfType is a shim that allows you to pass a callback to SentMessages.ForEach that is only invoked for sent messages of a particular type.
func NilSliceOf ¶
NilSliceOf wraps rapid.SliceOf, but returns nil instead of an empty slice for the 0-element case.
func RandomIdentifier ¶
func RandomIdentifier() *rapid.Generator[pastry.Identifier]
RandomIdentifier returns a property test generator that returns a single random Identifier.
func RandomProximity ¶
RandomProximity returns a property test generator that returns a single random Proximity.
func RoutedMessageOfType ¶
func RoutedMessageOfType[M pastry.Message](callback func(nextHop pastry.Node, source pastry.Identifier, target pastry.Identifier, msg M)) func(SentMessage)
RoutedMessageOfType is a shim that allows you to pass a callback to SentMessages.ForEach that is only invoked for routed messages of a particular type.
Types ¶
type SentMessage ¶
SentMessages is a record of one of the outgoing messages sent by a node in a test universe.
type SentMessages ¶
type SentMessages struct {
// contains filtered or unexported fields
}
SentMessages is a record of all of the outgoing messages sent by a node in a test universe.
func NewSentMessages ¶
func NewSentMessages(router *pastry.Router) *SentMessages
func (*SentMessages) Add ¶
func (sms *SentMessages) Add(sm SentMessage)
Add records a new sent message.
func (*SentMessages) ForEach ¶
func (sms *SentMessages) ForEach(callback func(sm SentMessage))
ForEach executes a callback against each sent message. This is typically used in test cases to check assertions against the message content. You can use MessageOfType and RoutedMessageOfType to create callbacks that will only be applied to sent (routed) messages of a particular type.
func (*SentMessages) Len ¶
func (sms *SentMessages) Len() int
Len returns the number of messages that were sent by this node.