pastrytest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package pastrytest provides various helpers for testing Pastry networks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(t *testing.T, f func(t *rapid.T, logger *slog.Logger))

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 NewLogger

func NewLogger(w io.Writer) *slog.Logger

func NilSliceOf

func NilSliceOf[T any](element *rapid.Generator[T]) *rapid.Generator[[]T]

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

func RandomProximity() *rapid.Generator[pastry.Proximity]

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.

func WithLogger

func WithLogger(t *testing.T, f func(t *testing.T, logger *slog.Logger))

WithLogger runs a test function while collecting any log and slog output that it produces. If the test fails, we will display the collected log output.

Types

type SentMessage

type SentMessage struct {
	Source pastry.Node
	Dest   pastry.Node
	Msg    pastry.Message
}

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.

Jump to

Keyboard shortcuts

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