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 ¶ added in v0.1.8
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 ¶ added in v0.1.8
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 ¶ added in v0.4.0
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 ¶ added in v0.4.0
func (m *MockAdapter) Append(ctx context.Context, streamID string, events []adapters.EventRecord, expectedVersion int64) ([]adapters.StoredEvent, error)
Append implements adapters.EventStoreAdapter.
func (*MockAdapter) Close ¶ added in v0.4.0
func (m *MockAdapter) Close() error
Close implements adapters.EventStoreAdapter.
func (*MockAdapter) GetLastPosition ¶ added in v0.4.0
func (m *MockAdapter) GetLastPosition(ctx context.Context) (uint64, error)
GetLastPosition implements adapters.EventStoreAdapter.
func (*MockAdapter) GetStreamInfo ¶ added in v0.4.0
func (m *MockAdapter) GetStreamInfo(ctx context.Context, streamID string) (*adapters.StreamInfo, error)
GetStreamInfo implements adapters.EventStoreAdapter.
func (*MockAdapter) Initialize ¶ added in v0.4.0
func (m *MockAdapter) Initialize(ctx context.Context) error
Initialize implements adapters.EventStoreAdapter.
func (*MockAdapter) Load ¶ added in v0.4.0
func (m *MockAdapter) Load(ctx context.Context, streamID string, fromVersion int64) ([]adapters.StoredEvent, error)
Load implements adapters.EventStoreAdapter.
func (*MockAdapter) LoadFromPosition ¶ added in v0.4.3
func (m *MockAdapter) LoadFromPosition(ctx context.Context, fromPosition uint64, limit int) ([]adapters.StoredEvent, error)
LoadFromPosition implements adapters.SubscriptionAdapter.
func (*MockAdapter) SubscribeAll ¶ added in v0.4.3
func (m *MockAdapter) SubscribeAll(ctx context.Context, fromPosition uint64, opts ...adapters.SubscriptionOptions) (<-chan adapters.StoredEvent, error)
SubscribeAll implements adapters.SubscriptionAdapter.
func (*MockAdapter) SubscribeCategory ¶ added in v0.4.3
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 ¶ added in v0.4.3
func (m *MockAdapter) SubscribeStream(ctx context.Context, streamID string, fromVersion int64, opts ...adapters.SubscriptionOptions) (<-chan adapters.StoredEvent, error)
SubscribeStream implements adapters.SubscriptionAdapter.
type MockProjection ¶ added in v0.4.0
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 ¶ added in v0.4.0
func (p *MockProjection) Apply(ctx context.Context, event mink.StoredEvent) error
Apply implements mink.InlineProjection.
func (*MockProjection) HandledEvents ¶ added in v0.4.0
func (p *MockProjection) HandledEvents() []string
HandledEvents implements mink.InlineProjection.
func (*MockProjection) Name ¶ added in v0.4.0
func (p *MockProjection) Name() string
Name implements mink.InlineProjection.
type MockT ¶ added in v0.4.0
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 ¶ added in v0.4.0
RunWithMockT runs a function with a MockT and waits for completion. This handles runtime.Goexit() calls from Fatal/FailNow.
type Order ¶ added in v0.1.8
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 ¶ added in v0.1.8
ApplyEvent applies historical events to rebuild state.
func (*Order) TotalAmount ¶ added in v0.1.8
TotalAmount calculates the total order amount.
type OrderCancelled ¶ added in v0.1.8
OrderCancelled event for testing.
type OrderCreated ¶ added in v0.1.8
OrderCreated event for testing.
type OrderReadModel ¶ added in v0.1.8
type OrderReadModel struct {
// contains filtered or unexported fields
}
OrderReadModel maintains a collection of order summaries.
func NewOrderReadModel ¶ added in v0.1.8
func NewOrderReadModel() *OrderReadModel
NewOrderReadModel creates a new read model.
func (*OrderReadModel) Apply ¶ added in v0.1.8
func (rm *OrderReadModel) Apply(event mink.StoredEvent) error
Apply processes an event and updates the read model.
func (*OrderReadModel) Count ¶ added in v0.1.8
func (rm *OrderReadModel) Count() int
Count returns the number of orders in the read model.
func (*OrderReadModel) Get ¶ added in v0.1.8
func (rm *OrderReadModel) Get(orderID string) *OrderSummary
Get returns an order summary by ID.
func (*OrderReadModel) UpdateCount ¶ added in v0.1.8
func (rm *OrderReadModel) UpdateCount() int
UpdateCount returns the number of updates processed.
type OrderShipped ¶ added in v0.1.8
type OrderShipped struct {
OrderID string `json:"orderId"`
TrackingNumber string `json:"trackingNumber"`
}
OrderShipped event for testing.
type OrderSummary ¶ added in v0.1.8
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 ¶ added in v0.4.0
TestCommand is a mock command for testing middleware.
func (*TestCommand) AggregateID ¶ added in v0.4.0
func (c *TestCommand) AggregateID() string
AggregateID implements mink.Command.
func (*TestCommand) AggregateType ¶ added in v0.4.0
func (c *TestCommand) AggregateType() string
AggregateType implements mink.Command.
func (*TestCommand) CommandType ¶ added in v0.4.0
func (c *TestCommand) CommandType() string
CommandType implements mink.Command.
func (*TestCommand) Validate ¶ added in v0.4.0
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.