testx

package
v2.8.8 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockClock

func MockClock(t *testing.T) *clock.Mock

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

func MockEventsGetAll[T events.Event](t *testing.T, m *MockEvents, predicates ...func(T) bool) []T

MockEventsGetAll returns all recorded events of type T that match every predicate, in the order they were recorded.

func MockEventsGetSingle

func MockEventsGetSingle[T events.Event](t *testing.T, m *MockEvents, predicates ...func(T) bool) T

MockEventsGetSingle returns the single recorded event of type T matching all predicates, failing the test unless exactly one such event exists.

func MockEventsHasNone

func MockEventsHasNone[T events.Event](t *testing.T, m *MockEvents, predicates ...func(T) bool)

MockEventsHasNone fails the test if any recorded event of type T matches all predicates.

func MockEventsHasSome

func MockEventsHasSome[T events.Event](t *testing.T, m *MockEvents, predicates ...func(T) bool) []T

MockEventsHasSome returns the recorded events of type T matching all predicates, failing the test if there are none.

func MustTransact

func MustTransact(t *testing.T, db *sqlx.DB, fn func(ctx ql.TxContext))

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

func MustTransactErr(t *testing.T, db *sqlx.DB, fn func(ctx ql.TxContext) error)

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.

func NewConnection

func NewConnection(t *testing.T, schemaTable string) *sqlx.DB

NewConnection creates a temporary postgres database and applies schema files from the ./sql directory.

Types

type ConfluentRegistry added in v2.6.5

type ConfluentRegistry struct {
	URL string
	// contains filtered or unexported fields
}

ConfluentRegistry is an in-memory mock of the Confluent schema registry REST API. It only supports schema registration and lookup by id and is meant for tests only.

func MockConfluentRegistry added in v2.6.5

func MockConfluentRegistry(t *testing.T) *ConfluentRegistry

MockConfluentRegistry starts an in-memory schema registry served over HTTP. The server is shut down automatically on test cleanup. Use Client to obtain a confluent client pointing at it.

func (*ConfluentRegistry) Client added in v2.6.5

func (r *ConfluentRegistry) Client() confluent.Client

Client returns a confluent schema registry client connected to this mock.

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

func KafkaCluster(t *testing.T) *Kafka

KafkaCluster starts a single-broker in-memory mock Kafka cluster and a background producer. The cluster and producer are closed automatically on test cleanup.

Warning: The mock cluster does not support topic creation with AdminClient.CreateTopic, you need to create topics via the CreateTopic method on the mock cluster

func (*Kafka) Consumer added in v2.6.4

func (k *Kafka) Consumer() *kafka.Consumer

func (*Kafka) CreateTopic added in v2.6.4

func (k *Kafka) CreateTopic(name string, partitions int)

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.

func (*Kafka) Producer added in v2.7.0

func (k *Kafka) Producer() *kafka.Producer

func (*Kafka) Send added in v2.6.4

func (k *Kafka) Send(msg *kafka.Message)

Send queues msg for asynchronous delivery to the cluster.

func (*Kafka) TestConsumer added in v2.7.0

func (k *Kafka) TestConsumer(topic string, moreTopics ...string) *KafkaConsumer

TestConsumer creates a consumer subscribed to the given topic(s). The consumer is closed automatically on test cleanup.

type KafkaConsumer added in v2.6.4

type KafkaConsumer struct {
	Consumer *kafka.Consumer
	// contains filtered or unexported fields
}

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
	// 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) Events

func (m *MockEvents) Events() []events.Event

Events returns a copy of the recorded events.

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.

Jump to

Keyboard shortcuts

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