Documentation
¶
Overview ¶
Package testutil provides shared test utilities and mocks for cdev tests.
Index ¶
- func AssertContains(t *testing.T, s, substr, msg string)
- func AssertEqual(t *testing.T, expected, actual interface{}, msg string)
- func AssertError(t *testing.T, err error, msg string)
- func AssertFalse(t *testing.T, condition bool, msg string)
- func AssertNil(t *testing.T, value interface{}, msg string)
- func AssertNoError(t *testing.T, err error, msg string)
- func AssertNotNil(t *testing.T, value interface{}, msg string)
- func AssertTrue(t *testing.T, condition bool, msg string)
- type MockEventHub
- func (m *MockEventHub) IsRunning() bool
- func (m *MockEventHub) Publish(e events.Event)
- func (m *MockEventHub) PublishedEvents() []events.Event
- func (m *MockEventHub) Start() error
- func (m *MockEventHub) Stop() error
- func (m *MockEventHub) Subscribe(sub ports.Subscriber)
- func (m *MockEventHub) SubscriberCount() int
- func (m *MockEventHub) Unsubscribe(id string)
- type MockSubscriber
- func (m *MockSubscriber) ClearEvents()
- func (m *MockSubscriber) Close() error
- func (m *MockSubscriber) Done() <-chan struct{}
- func (m *MockSubscriber) EventCount() int
- func (m *MockSubscriber) Events() []events.Event
- func (m *MockSubscriber) ID() string
- func (m *MockSubscriber) IsClosed() bool
- func (m *MockSubscriber) Send(e events.Event) error
- func (m *MockSubscriber) SetSendError(err error)
- func (m *MockSubscriber) SetSendFunc(fn func(events.Event) error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertContains ¶
AssertContains checks if a string contains a substring.
func AssertEqual ¶
AssertEqual is a simple equality assertion helper.
func AssertError ¶
AssertError asserts that an error is not nil.
func AssertFalse ¶
AssertFalse asserts that a condition is false.
func AssertNoError ¶
AssertNoError asserts that an error is nil.
func AssertNotNil ¶
AssertNotNil asserts that a value is not nil.
Types ¶
type MockEventHub ¶
type MockEventHub struct {
// contains filtered or unexported fields
}
MockEventHub implements ports.EventHub for testing.
func NewMockEventHub ¶
func NewMockEventHub() *MockEventHub
NewMockEventHub creates a new mock event hub.
func (*MockEventHub) IsRunning ¶
func (m *MockEventHub) IsRunning() bool
IsRunning returns true if the hub was started and not stopped.
func (*MockEventHub) Publish ¶
func (m *MockEventHub) Publish(e events.Event)
Publish records the event.
func (*MockEventHub) PublishedEvents ¶
func (m *MockEventHub) PublishedEvents() []events.Event
PublishedEvents returns all published events.
func (*MockEventHub) Subscribe ¶
func (m *MockEventHub) Subscribe(sub ports.Subscriber)
Subscribe records the subscriber.
func (*MockEventHub) SubscriberCount ¶
func (m *MockEventHub) SubscriberCount() int
SubscriberCount returns the number of subscribers.
func (*MockEventHub) Unsubscribe ¶
func (m *MockEventHub) Unsubscribe(id string)
Unsubscribe removes a subscriber by ID.
type MockSubscriber ¶
type MockSubscriber struct {
// contains filtered or unexported fields
}
MockSubscriber implements ports.Subscriber for testing.
func NewMockSubscriber ¶
func NewMockSubscriber(id string) *MockSubscriber
NewMockSubscriber creates a new mock subscriber.
func (*MockSubscriber) ClearEvents ¶
func (m *MockSubscriber) ClearEvents()
ClearEvents removes all recorded events.
func (*MockSubscriber) Close ¶
func (m *MockSubscriber) Close() error
Close marks the subscriber as closed.
func (*MockSubscriber) Done ¶
func (m *MockSubscriber) Done() <-chan struct{}
Done returns a channel that's closed when the subscriber is done.
func (*MockSubscriber) EventCount ¶
func (m *MockSubscriber) EventCount() int
EventCount returns the number of received events.
func (*MockSubscriber) Events ¶
func (m *MockSubscriber) Events() []events.Event
Events returns all received events.
func (*MockSubscriber) IsClosed ¶
func (m *MockSubscriber) IsClosed() bool
IsClosed returns whether the subscriber was closed.
func (*MockSubscriber) Send ¶
func (m *MockSubscriber) Send(e events.Event) error
Send records the event and returns any configured error.
func (*MockSubscriber) SetSendError ¶
func (m *MockSubscriber) SetSendError(err error)
SetSendError configures an error to return on Send.
func (*MockSubscriber) SetSendFunc ¶
func (m *MockSubscriber) SetSendFunc(fn func(events.Event) error)
SetSendFunc sets a custom function for Send behavior.