testutil

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupSchema

func CleanupSchema(ctx context.Context, db *sql.DB, schema string) error

CleanupSchema drops a schema and all its objects. The schema name should come from UniqueSchema() which generates safe names.

func MustPostgresDB

func MustPostgresDB(ctx context.Context, connStr string) *sql.DB

MustPostgresDB returns a database connection or panics.

func PostgresDB

func PostgresDB(ctx context.Context, connStr string) (*sql.DB, error)

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

func UniqueSchema(prefix string) string

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 NewMockT added in v0.4.0

func NewMockT() *MockT

NewMockT creates a new MockT instance.

func RunWithMockT added in v0.4.0

func RunWithMockT(fn func(m *MockT)) *MockT

RunWithMockT runs a function with a MockT and waits for completion. This handles runtime.Goexit() calls from Fatal/FailNow.

func (*MockT) Error added in v0.4.0

func (m *MockT) Error(args ...any)

Error implements testing.TB.

func (*MockT) Errorf added in v0.4.0

func (m *MockT) Errorf(format string, args ...any)

Errorf implements testing.TB.

func (*MockT) Fail added in v0.4.0

func (m *MockT) Fail()

Fail implements testing.TB.

func (*MockT) FailNow added in v0.4.0

func (m *MockT) FailNow()

FailNow implements testing.TB.

func (*MockT) Failed added in v0.4.0

func (m *MockT) Failed() bool

Failed implements testing.TB.

func (*MockT) Fatal added in v0.4.0

func (m *MockT) Fatal(args ...any)

Fatal implements testing.TB.

func (*MockT) Fatalf added in v0.4.0

func (m *MockT) Fatalf(format string, args ...any)

Fatalf implements testing.TB.

func (*MockT) Helper added in v0.4.0

func (m *MockT) Helper()

Helper implements testing.TB.

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 NewOrder added in v0.1.8

func NewOrder(id string) *Order

NewOrder creates a new Order aggregate for testing.

func (*Order) AddItem added in v0.1.8

func (o *Order) AddItem(sku string, qty int, price float64) error

AddItem adds an item to the order.

func (*Order) ApplyEvent added in v0.1.8

func (o *Order) ApplyEvent(event interface{}) error

ApplyEvent applies historical events to rebuild state.

func (*Order) Cancel added in v0.1.8

func (o *Order) Cancel(reason string) error

Cancel cancels the order.

func (*Order) Create added in v0.1.8

func (o *Order) Create(customerID string) error

Create initializes the order.

func (*Order) Ship added in v0.1.8

func (o *Order) Ship(trackingNumber string) error

Ship marks the order as shipped.

func (*Order) TotalAmount added in v0.1.8

func (o *Order) TotalAmount() float64

TotalAmount calculates the total order amount.

type OrderCancelled added in v0.1.8

type OrderCancelled struct {
	OrderID string `json:"orderId"`
	Reason  string `json:"reason"`
}

OrderCancelled event for testing.

type OrderCreated added in v0.1.8

type OrderCreated struct {
	OrderID    string `json:"orderId"`
	CustomerID string `json:"customerId"`
}

OrderCreated event for testing.

type OrderItem added in v0.1.8

type OrderItem struct {
	SKU      string
	Quantity int
	Price    float64
}

OrderItem represents an item in an order.

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

type TestCommand struct {
	ID         string
	ShouldFail bool
}

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.

Jump to

Keyboard shortcuts

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