Documentation
¶
Overview ¶
Package testutil provides test utilities and fixtures for go-mink.
Package testutil provides test utilities and fixtures for go-mink.
Package testutil provides test utilities and fixtures for testing go-mink applications.
Package testutil provides test utilities and fixtures for testing go-mink applications.
Package testutil provides test utilities and fixtures for testing go-mink applications.
Package testutil provides utilities for integration testing. It provides helpers for connecting to test infrastructure and waiting for services to be ready.
Index ¶
- func CleanupSchema(ctx context.Context, db *sql.DB, schema string) error
- func MustPostgresDB(ctx context.Context, connStr string) *sql.DB
- func PostgresDB(ctx context.Context, connStr string) (*sql.DB, error)
- func RegisterTestEvents(store *mink.EventStore)
- func UniqueSchema(prefix string) string
- type ItemAdded
- type MockAdapter
- func (m *MockAdapter) Append(ctx context.Context, streamID string, events []adapters.EventRecord, ...) ([]adapters.StoredEvent, error)
- func (m *MockAdapter) Close() error
- func (m *MockAdapter) GetLastPosition(ctx context.Context) (uint64, error)
- func (m *MockAdapter) GetStreamInfo(ctx context.Context, streamID string) (*adapters.StreamInfo, error)
- func (m *MockAdapter) Initialize(ctx context.Context) error
- func (m *MockAdapter) Load(ctx context.Context, streamID string, fromVersion int64) ([]adapters.StoredEvent, error)
- func (m *MockAdapter) LoadFromPosition(ctx context.Context, fromPosition uint64, limit int) ([]adapters.StoredEvent, error)
- func (m *MockAdapter) SubscribeAll(ctx context.Context, fromPosition uint64, opts ...adapters.SubscriptionOptions) (<-chan adapters.StoredEvent, error)
- func (m *MockAdapter) SubscribeCategory(ctx context.Context, category string, fromPosition uint64, ...) (<-chan adapters.StoredEvent, error)
- func (m *MockAdapter) SubscribeStream(ctx context.Context, streamID string, fromVersion int64, ...) (<-chan adapters.StoredEvent, error)
- type MockProjection
- type MockT
- type Order
- type OrderCancelled
- type OrderCreated
- type OrderItem
- type OrderReadModel
- type OrderShipped
- type OrderSummary
- type TestCommand
- type TestConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupSchema ¶
CleanupSchema drops a schema and all its objects. The schema name should come from UniqueSchema() which generates safe names.
func MustPostgresDB ¶
MustPostgresDB returns a database connection or panics.
func PostgresDB ¶
PostgresDB returns a database connection for PostgreSQL testing. It waits for the database to be ready with retries.
func RegisterTestEvents ¶
func RegisterTestEvents(store *mink.EventStore)
RegisterTestEvents registers test event types with the store.
func UniqueSchema ¶
UniqueSchema generates a unique schema name for testing. The generated names contain only alphanumeric characters and underscores, making them safe for use in SQL queries.
Types ¶
type ItemAdded ¶
type ItemAdded struct {
OrderID string `json:"orderId"`
SKU string `json:"sku"`
Quantity int `json:"quantity"`
Price float64 `json:"price"`
}
ItemAdded event for testing.
type MockAdapter ¶
type MockAdapter struct {
AppendErr error
LoadErr error
GetStreamInfoErr error
GetLastPositionErr error
LoadFromPositionErr error
Events []adapters.StoredEvent
}
MockAdapter is a mock implementation of adapters.EventStoreAdapter for testing.
func (*MockAdapter) Append ¶
func (m *MockAdapter) Append(ctx context.Context, streamID string, events []adapters.EventRecord, expectedVersion int64) ([]adapters.StoredEvent, error)
Append implements adapters.EventStoreAdapter.
func (*MockAdapter) Close ¶
func (m *MockAdapter) Close() error
Close implements adapters.EventStoreAdapter.
func (*MockAdapter) GetLastPosition ¶
func (m *MockAdapter) GetLastPosition(ctx context.Context) (uint64, error)
GetLastPosition implements adapters.EventStoreAdapter.
func (*MockAdapter) GetStreamInfo ¶
func (m *MockAdapter) GetStreamInfo(ctx context.Context, streamID string) (*adapters.StreamInfo, error)
GetStreamInfo implements adapters.EventStoreAdapter.
func (*MockAdapter) Initialize ¶
func (m *MockAdapter) Initialize(ctx context.Context) error
Initialize implements adapters.EventStoreAdapter.
func (*MockAdapter) Load ¶
func (m *MockAdapter) Load(ctx context.Context, streamID string, fromVersion int64) ([]adapters.StoredEvent, error)
Load implements adapters.EventStoreAdapter.
func (*MockAdapter) LoadFromPosition ¶
func (m *MockAdapter) LoadFromPosition(ctx context.Context, fromPosition uint64, limit int) ([]adapters.StoredEvent, error)
LoadFromPosition implements adapters.SubscriptionAdapter.
func (*MockAdapter) SubscribeAll ¶
func (m *MockAdapter) SubscribeAll(ctx context.Context, fromPosition uint64, opts ...adapters.SubscriptionOptions) (<-chan adapters.StoredEvent, error)
SubscribeAll implements adapters.SubscriptionAdapter.
func (*MockAdapter) SubscribeCategory ¶
func (m *MockAdapter) SubscribeCategory(ctx context.Context, category string, fromPosition uint64, opts ...adapters.SubscriptionOptions) (<-chan adapters.StoredEvent, error)
SubscribeCategory implements adapters.SubscriptionAdapter.
func (*MockAdapter) SubscribeStream ¶
func (m *MockAdapter) SubscribeStream(ctx context.Context, streamID string, fromVersion int64, opts ...adapters.SubscriptionOptions) (<-chan adapters.StoredEvent, error)
SubscribeStream implements adapters.SubscriptionAdapter.
type MockProjection ¶
type MockProjection struct {
ProjectionName string
EventTypes []string
ApplyErr error
Applied []mink.StoredEvent
}
MockProjection is a mock implementation of mink.InlineProjection for testing.
func (*MockProjection) Apply ¶
func (p *MockProjection) Apply(ctx context.Context, event mink.StoredEvent) error
Apply implements mink.InlineProjection.
func (*MockProjection) HandledEvents ¶
func (p *MockProjection) HandledEvents() []string
HandledEvents implements mink.InlineProjection.
func (*MockProjection) Name ¶
func (p *MockProjection) Name() string
Name implements mink.InlineProjection.
type MockT ¶
type MockT struct {
testing.TB // embed to satisfy unexported methods
Failed_ bool
Fatal_ bool
Message string
Logs []string
}
MockT is a mock testing.TB that captures test failures for testing. It is used to test functions that call testing.T methods like Fatal, Error, etc.
func RunWithMockT ¶
RunWithMockT runs a function with a MockT and waits for completion. This handles runtime.Goexit() calls from Fatal/FailNow.
type Order ¶
type Order struct {
mink.AggregateBase
CustomerID string
Items []OrderItem
Status string
TrackingNumber string
CancelReason string
}
Order is a test aggregate for E2E tests.
func (*Order) ApplyEvent ¶
ApplyEvent applies historical events to rebuild state.
func (*Order) TotalAmount ¶
TotalAmount calculates the total order amount.
type OrderCancelled ¶
OrderCancelled event for testing.
type OrderCreated ¶
OrderCreated event for testing.
type OrderReadModel ¶
type OrderReadModel struct {
// contains filtered or unexported fields
}
OrderReadModel maintains a collection of order summaries.
func NewOrderReadModel ¶
func NewOrderReadModel() *OrderReadModel
NewOrderReadModel creates a new read model.
func (*OrderReadModel) Apply ¶
func (rm *OrderReadModel) Apply(event mink.StoredEvent) error
Apply processes an event and updates the read model.
func (*OrderReadModel) Count ¶
func (rm *OrderReadModel) Count() int
Count returns the number of orders in the read model.
func (*OrderReadModel) Get ¶
func (rm *OrderReadModel) Get(orderID string) *OrderSummary
Get returns an order summary by ID.
func (*OrderReadModel) UpdateCount ¶
func (rm *OrderReadModel) UpdateCount() int
UpdateCount returns the number of updates processed.
type OrderShipped ¶
type OrderShipped struct {
OrderID string `json:"orderId"`
TrackingNumber string `json:"trackingNumber"`
}
OrderShipped event for testing.
type OrderSummary ¶
type OrderSummary struct {
OrderID string
CustomerID string
ItemCount int
TotalAmount float64
Status string
TrackingNumber string
}
OrderSummary is a simple read model for orders.
type TestCommand ¶
TestCommand is a mock command for testing middleware.
func (*TestCommand) AggregateID ¶
func (c *TestCommand) AggregateID() string
AggregateID implements mink.Command.
func (*TestCommand) AggregateType ¶
func (c *TestCommand) AggregateType() string
AggregateType implements mink.Command.
func (*TestCommand) CommandType ¶
func (c *TestCommand) CommandType() string
CommandType implements mink.Command.
func (*TestCommand) Validate ¶
func (c *TestCommand) Validate() error
Validate implements mink.Command.
type TestConfig ¶
type TestConfig struct {
PostgresURL string
}
TestConfig holds configuration for test infrastructure.
func DefaultConfig ¶
func DefaultConfig() *TestConfig
DefaultConfig returns the default test configuration from environment variables.