eventbustest

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package eventbustest tests event bus implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Basic

func Basic(t *testing.T, newBus EventBusFactory, opts ...Option)

Basic tests the basic functionality of an event bus. The test is successful if multiple subscribers of the same event receive the event when it is published.

func CancelSubscription

func CancelSubscription(t *testing.T, newBus EventBusFactory, opts ...Option)

CancelSubscription cancels a subscription context and ensures that no further events are received by the subscriber.

func PublishMultipleEvents

func PublishMultipleEvents(t *testing.T, newBus EventBusFactory, opts ...Option)

PublishMultipleEvents publishes multiple events to the event bus and expects certain subscribers to receive certain events. It takes a *testing.T, an EventBusFactory and optional Options. The test is successful if the "foo" and "baz" events are received by their respective subscribers after being published.

func RunCore added in v0.1.2

func RunCore(t *testing.T, newBus EventBusFactory, opts ...Option)

RunCore tests all functions of the event bus.

func RunWildcard added in v0.1.2

func RunWildcard(t *testing.T, newBus EventBusFactory, opts ...Option)

func SubscribeCanceledContext

func SubscribeCanceledContext(t *testing.T, newBus EventBusFactory, opts ...Option)

SubscribeCanceledContext tests the behavior of a subscription when its context is canceled. The test is successful if the subscription is closed within 50 milliseconds.

func SubscribeMultipleEvents

func SubscribeMultipleEvents(t *testing.T, newBus EventBusFactory, opts ...Option)

SubscribeMultipleEvents subscribes to multiple events at once and tests if the subscriber receives events published to any of the subscribed events.

Types

type EventBusFactory

type EventBusFactory func(codec.Encoding) event.Bus

EventBusFactory creates an event.Bus from an codec.Encoding.

type Expectations

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

Expectations provides a way to expect subscribed events and errors. It has methods for expecting nothing to happen, expecting any of the given events to be received, expecting all of the given events to be received, and expecting the event and error channels of a subscription to be closed.

func Expect

func Expect(ctx context.Context) *Expectations

Expect returns a new Expectation for expecting subscribed events and errors.

func (*Expectations) Apply

func (ex *Expectations) Apply(t *testing.T)

Apply applies the result to the provided test. If the result is an error, t.Fatal(err) is called.

func (*Expectations) Closed

func (ex *Expectations) Closed(sub Subscription, timeout time.Duration)

Closed expects the event and error channels of a subscription to be closed within the given duration.

func (*Expectations) Event

func (ex *Expectations) Event(sub Subscription, timeout time.Duration, names ...string)

Event expects any of the given events to be received within the given duration.

func (*Expectations) Events

func (ex *Expectations) Events(sub Subscription, timeout time.Duration, names ...string)

Events expects all of the given events to be received within the given duration.

func (*Expectations) Nothing

func (ex *Expectations) Nothing(sub Subscription, timeout time.Duration)

Nothing expectes that nothing happens to the event and error channel of a subscription within the given duration.

func (*Expectations) Result

func (ex *Expectations) Result() error

Result returns the result of the expectations.

type Option added in v0.1.2

type Option func(*config)

Option is a function type that modifies the configuration of an event bus test. It takes a pointer to a config struct as its argument and modifies its fields. Option functions are used to configure event bus tests with custom options. The Cleanup function is one such option that takes a testing.T instance and an event.Bus instance to clean up the event bus after a test is completed.

func Cleanup added in v0.1.2

func Cleanup[Bus event.Bus](cleanup func(Bus) error) Option

Cleanup returns an Option that sets a function to clean up an event bus after testing is complete. The function takes an event.Bus as input and returns an error. This Option is used in the configure function to set up a configuration for testing, and in the Cleanup method to execute the cleanup function with the provided event bus. If the cleanup function returns an error, Cleanup will call t.Fatalf with a formatted error message.

type Subscription

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

A Subscription wraps the event and and error channels from an event subscription

func MustSub

func MustSub(events <-chan event.Event, errs <-chan error, err error) Subscription

MustSub does the same as Sub, but accepts an additional error argument so it can be used like this:

var bus event.Bus
sub := MustSub(bus.Subscribe(context.TODO(), "foo"))

MustSub panics if error is not nil.

func Sub

func Sub(events <-chan event.Event, errs <-chan error) Subscription

Sub wraps the given event and error channels in a Subscription.

Jump to

Keyboard shortcuts

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