Documentation
¶
Index ¶
- func MockClock(t *testing.T) *clock.Mock
- func MockEventsGetAll[T events.Event](t *testing.T, m *MockEvents, predicates ...func(T) bool) []T
- func MockEventsGetSingle[T events.Event](t *testing.T, m *MockEvents, predicates ...func(T) bool) T
- func MockEventsHasNone[T events.Event](t *testing.T, m *MockEvents, predicates ...func(T) bool)
- func MockEventsHasSome[T events.Event](t *testing.T, m *MockEvents, predicates ...func(T) bool) []T
- func MustTransact(t *testing.T, db *sqlx.DB, fn func(ctx ql.TxContext))
- func MustTransactErr(t *testing.T, db *sqlx.DB, fn func(ctx ql.TxContext) error)
- func NewConnection(t *testing.T, schemaTable string) *sqlx.DB
- type Kafka
- type KafkaConsumer
- type MockEvents
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MockClock ¶
MockClock replaces the global clock with a mock fixed at 2026-01-01 09:00:00 UTC and returns it for advancing time during the test. The previous clock is restored on test cleanup. It panics if a mock clock is already installed, since the global clock cannot be shared across concurrent tests.
func MockEventsGetAll ¶
MockEventsGetAll returns all recorded events of type T that match every predicate, in the order they were recorded.
func MockEventsGetSingle ¶
MockEventsGetSingle returns the single recorded event of type T matching all predicates, failing the test unless exactly one such event exists.
func MockEventsHasNone ¶
MockEventsHasNone fails the test if any recorded event of type T matches all predicates.
func MockEventsHasSome ¶
MockEventsHasSome returns the recorded events of type T matching all predicates, failing the test if there are none.
func MustTransact ¶
MustTransact runs fn inside a new transaction bound to the test context and commits it. The test fails if the transaction cannot be opened or committed.
func MustTransactErr ¶
MustTransactErr runs fn inside a new transaction bound to the test context and fails the test if fn returns an error. On success the transaction is committed.
Types ¶
type Kafka ¶ added in v2.6.4
type Kafka struct {
BootstrapServers string
// contains filtered or unexported fields
}
Kafka is a handle to a running in-memory mock Kafka cluster together with a producer for sending messages to it.
func KafkaCluster ¶ added in v2.6.4
KafkaCluster starts a single-broker in-memory mock Kafka cluster and a background producer. The cluster and producer are closed automatically on test cleanup.
func (*Kafka) Consumer ¶ added in v2.6.4
func (k *Kafka) Consumer(topic string, moreTopics ...string) *KafkaConsumer
Consumer creates a consumer subscribed to the given topic(s). The consumer is closed automatically on test cleanup.
func (*Kafka) CreateTopic ¶ added in v2.6.4
CreateTopic creates a topic with the given number of partitions and a replication factor of 1. The test fails if the topic cannot be created.
type KafkaConsumer ¶ added in v2.6.4
KafkaConsumer is a handle to a Kafka consumer subscribed to one or more topics.
func (*KafkaConsumer) Message ¶ added in v2.6.4
func (c *KafkaConsumer) Message() *kafka.Message
Message reads the next message, blocking essentially indefinitely until one arrives.
func (*KafkaConsumer) MessageTimeout ¶ added in v2.6.4
func (c *KafkaConsumer) MessageTimeout(timeout time.Duration) *kafka.Message
MessageTimeout reads the next message, failing the test if none arrives within timeout.
type MockEvents ¶
type MockEvents struct {
Testing *testing.T
Events []events.Event
// contains filtered or unexported fields
}
MockEvents is an events.Sender that records events instead of dispatching them. Events sent transactionally are recorded only after the transaction commits.
func CaptureEvents ¶
func CaptureEvents(t *testing.T) *MockEvents
CaptureEvents replaces the global events sender with a MockEvents that records all sent events and returns it. The previous sender is restored on test cleanup. It panics if events are already being captured, since the global sender cannot be shared across concurrent tests.
func (*MockEvents) Close ¶
func (m *MockEvents) Close() error
Close is a no-op that satisfies the events.Sender interface.
func (*MockEvents) SendAsync ¶
func (m *MockEvents) SendAsync(_ context.Context, event events.Event)
SendAsync serializes the event (failing the test on error) and records it immediately.
func (*MockEvents) SendInTx ¶
func (m *MockEvents) SendInTx(ctx context.Context, _ sqlx.ExecerContext, event events.Event) error
SendInTx serializes the event (failing the test on error) and records it once the transaction in ctx commits.