Documentation ¶
Overview ¶
Package eventbustest tests event bus implementations.
Index ¶
- func Basic(t *testing.T, newBus EventBusFactory, opts ...Option)
- func CancelSubscription(t *testing.T, newBus EventBusFactory, opts ...Option)
- func PublishMultipleEvents(t *testing.T, newBus EventBusFactory, opts ...Option)
- func RunCore(t *testing.T, newBus EventBusFactory, opts ...Option)
- func RunWildcard(t *testing.T, newBus EventBusFactory, opts ...Option)
- func SubscribeCanceledContext(t *testing.T, newBus EventBusFactory, opts ...Option)
- func SubscribeMultipleEvents(t *testing.T, newBus EventBusFactory, opts ...Option)
- type EventBusFactory
- type Expectations
- func (ex *Expectations) Apply(t *testing.T)
- func (ex *Expectations) Closed(sub Subscription, timeout time.Duration)
- func (ex *Expectations) Event(sub Subscription, timeout time.Duration, names ...string)
- func (ex *Expectations) Events(sub Subscription, timeout time.Duration, names ...string)
- func (ex *Expectations) Nothing(sub Subscription, timeout time.Duration)
- func (ex *Expectations) Result() error
- type Option
- type Subscription
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 ¶
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
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.