Documentation
¶
Overview ¶
Package eventtest provides event-bus test doubles and assertions for the generic eventbus package: mock publisher/subscriber, a collecting event handler, signing helpers and event/security assertions.
Index ¶
- type EventAssertions
- func (a *EventAssertions) AssertEventData(event *eventbus.BaseEvent, expectedData map[string]any, msgAndArgs ...any) bool
- func (a *EventAssertions) AssertEventNotPublished(publisher *MockEventPublisher, eventType string, msgAndArgs ...any) bool
- func (a *EventAssertions) AssertEventOrder(publisher *MockEventPublisher, expectedOrder []string, msgAndArgs ...any) bool
- func (a *EventAssertions) AssertEventPublished(publisher *MockEventPublisher, eventType string, msgAndArgs ...any) bool
- func (a *EventAssertions) AssertEventStructure(event *eventbus.BaseEvent, msgAndArgs ...any) bool
- func (a *EventAssertions) AssertEventTimestamps(events []eventbus.BaseEvent, msgAndArgs ...any) bool
- type MockEventPublisher
- func (m *MockEventPublisher) ClearPublishedEvents()
- func (m *MockEventPublisher) Close() error
- func (m *MockEventPublisher) GetPublishedEvents() []eventbus.BaseEvent
- func (m *MockEventPublisher) GetPublishedEventsOfType(eventType string) []eventbus.BaseEvent
- func (m *MockEventPublisher) Publish(ctx context.Context, event *eventbus.BaseEvent) error
- func (m *MockEventPublisher) TestConnection() error
- type MockEventSubscriber
- type SecurityAssertions
- func (a *SecurityAssertions) AssertEventExpired(event *eventbus.BaseEvent, expiryWindow time.Duration, msgAndArgs ...any) bool
- func (a *SecurityAssertions) AssertEventNotExpired(event *eventbus.BaseEvent, expiryWindow time.Duration, msgAndArgs ...any) bool
- func (a *SecurityAssertions) AssertRequiredClaims(event *eventbus.BaseEvent, requiredClaims []string, msgAndArgs ...any) bool
- func (a *SecurityAssertions) AssertSignatureInvalid(signedEvent *eventbus.SignedEvent, config *eventbus.SignatureConfig, ...) bool
- func (a *SecurityAssertions) AssertSignatureValid(signedEvent *eventbus.SignedEvent, config *eventbus.SignatureConfig, ...) bool
- type SecurityTestHelper
- type TestEventHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventAssertions ¶
type EventAssertions struct {
// contains filtered or unexported fields
}
func NewEventAssertions ¶
func NewEventAssertions(t assert.TestingT) *EventAssertions
NewEventAssertions creates new event assertion helper
func (*EventAssertions) AssertEventData ¶
func (a *EventAssertions) AssertEventData(event *eventbus.BaseEvent, expectedData map[string]any, msgAndArgs ...any) bool
AssertEventData verifies event data contains expected fields
func (*EventAssertions) AssertEventNotPublished ¶
func (a *EventAssertions) AssertEventNotPublished(publisher *MockEventPublisher, eventType string, msgAndArgs ...any) bool
AssertEventNotPublished verifies that an event was not published
func (*EventAssertions) AssertEventOrder ¶
func (a *EventAssertions) AssertEventOrder(publisher *MockEventPublisher, expectedOrder []string, msgAndArgs ...any) bool
AssertEventOrder verifies events were published in correct order
func (*EventAssertions) AssertEventPublished ¶
func (a *EventAssertions) AssertEventPublished(publisher *MockEventPublisher, eventType string, msgAndArgs ...any) bool
AssertEventPublished verifies that an event was published
func (*EventAssertions) AssertEventStructure ¶
func (a *EventAssertions) AssertEventStructure(event *eventbus.BaseEvent, msgAndArgs ...any) bool
AssertEventStructure verifies basic event structure
func (*EventAssertions) AssertEventTimestamps ¶
func (a *EventAssertions) AssertEventTimestamps(events []eventbus.BaseEvent, msgAndArgs ...any) bool
AssertEventTimestamps verifies event timestamps are in chronological order
type MockEventPublisher ¶
type MockEventPublisher struct {
mock.Mock
PublishedEvents []eventbus.BaseEvent
// contains filtered or unexported fields
}
func NewMockEventPublisher ¶
func NewMockEventPublisher() *MockEventPublisher
NewMockEventPublisher creates a new mock event publisher
func (*MockEventPublisher) ClearPublishedEvents ¶
func (m *MockEventPublisher) ClearPublishedEvents()
ClearPublishedEvents clears the published events list
func (*MockEventPublisher) Close ¶
func (m *MockEventPublisher) Close() error
Close mocks publisher cleanup
func (*MockEventPublisher) GetPublishedEvents ¶
func (m *MockEventPublisher) GetPublishedEvents() []eventbus.BaseEvent
GetPublishedEvents returns all published events thread-safely
func (*MockEventPublisher) GetPublishedEventsOfType ¶
func (m *MockEventPublisher) GetPublishedEventsOfType(eventType string) []eventbus.BaseEvent
GetPublishedEventsOfType returns published events of a specific type
func (*MockEventPublisher) TestConnection ¶
func (m *MockEventPublisher) TestConnection() error
TestConnection mocks connection testing
type MockEventSubscriber ¶
MockEventSubscriber is a mock implementation of eventbus.Subscriber for testing
func NewMockEventSubscriber ¶
func NewMockEventSubscriber() *MockEventSubscriber
NewMockEventSubscriber creates a new mock event subscriber
func (*MockEventSubscriber) Close ¶
func (m *MockEventSubscriber) Close() error
Close mocks subscriber cleanup
func (*MockEventSubscriber) SimulateEvent ¶
func (m *MockEventSubscriber) SimulateEvent(event *eventbus.BaseEvent) error
SimulateEvent simulates receiving an event for testing
func (*MockEventSubscriber) Subscribe ¶
func (m *MockEventSubscriber) Subscribe(eventType string, queueName string, handler eventbus.EventHandler) error
Subscribe mocks event subscription
type SecurityAssertions ¶
type SecurityAssertions struct {
// contains filtered or unexported fields
}
SecurityAssertions provides specialized assertions for security testing
func NewSecurityAssertions ¶
func NewSecurityAssertions(t assert.TestingT) *SecurityAssertions
NewSecurityAssertions creates new security assertion helper
func (*SecurityAssertions) AssertEventExpired ¶
func (a *SecurityAssertions) AssertEventExpired(event *eventbus.BaseEvent, expiryWindow time.Duration, msgAndArgs ...any) bool
AssertEventExpired verifies event is expired
func (*SecurityAssertions) AssertEventNotExpired ¶
func (a *SecurityAssertions) AssertEventNotExpired(event *eventbus.BaseEvent, expiryWindow time.Duration, msgAndArgs ...any) bool
AssertEventNotExpired verifies event is not expired
func (*SecurityAssertions) AssertRequiredClaims ¶
func (a *SecurityAssertions) AssertRequiredClaims(event *eventbus.BaseEvent, requiredClaims []string, msgAndArgs ...any) bool
AssertRequiredClaims verifies event contains all required claims
func (*SecurityAssertions) AssertSignatureInvalid ¶
func (a *SecurityAssertions) AssertSignatureInvalid(signedEvent *eventbus.SignedEvent, config *eventbus.SignatureConfig, msgAndArgs ...any) bool
AssertSignatureInvalid verifies event signature is invalid
func (*SecurityAssertions) AssertSignatureValid ¶
func (a *SecurityAssertions) AssertSignatureValid(signedEvent *eventbus.SignedEvent, config *eventbus.SignatureConfig, msgAndArgs ...any) bool
AssertSignatureValid verifies event signature is valid
type SecurityTestHelper ¶
type SecurityTestHelper struct {
ValidSigningKey []byte
InvalidSigningKey []byte
ExpiredEvent *eventbus.BaseEvent
}
MockTime allows time-based testing
func NewSecurityTestHelper ¶
func NewSecurityTestHelper() *SecurityTestHelper
NewSecurityTestHelper creates security testing utilities
func (*SecurityTestHelper) CreateExpiredEvent ¶
func (h *SecurityTestHelper) CreateExpiredEvent() *eventbus.BaseEvent
CreateExpiredEvent creates an event with expired timestamp
func (*SecurityTestHelper) CreateTamperedEvent ¶
func (h *SecurityTestHelper) CreateTamperedEvent(originalEvent *eventbus.BaseEvent) *eventbus.BaseEvent
CreateTamperedEvent creates an event with tampered data
type TestEventHandler ¶
type TestEventHandler struct {
Events []eventbus.BaseEvent
EventChan chan *eventbus.BaseEvent
EventType string
ErrorChan chan error
// contains filtered or unexported fields
}
MockHTTPClient is a mock implementation of httpclient.Client for testing
func NewTestEventHandler ¶
func NewTestEventHandler() *TestEventHandler
NewTestEventHandler creates a new test event handler
func (*TestEventHandler) Clear ¶
func (h *TestEventHandler) Clear()
Clear clears all collected events
func (*TestEventHandler) GetEvents ¶
func (h *TestEventHandler) GetEvents() []eventbus.BaseEvent
GetEvents returns all collected events
func (*TestEventHandler) GetEventsOfType ¶
func (h *TestEventHandler) GetEventsOfType(eventType string) []eventbus.BaseEvent
GetEventsOfType returns events of a specific type