fixtures

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MockDatabaseType     = "mock"
	PostgresDatabaseType = "postgres"
	OracleDatabaseType   = "oracle"
	MongoDBDatabaseType  = "mongodb"
)

Database type constants

View Source
const (
	OpenConnectionsField = "open_connections"
	InUseField           = "in_use"
	IdleField            = "idle"
)

Database stats field constants

View Source
const (
	DefaultMigrationTable = "schema_migrations"
	OracleMigrationTable  = "SCHEMA_MIGRATIONS"
)

Migration table constants

View Source
const (
	DefaultOpenConnections = 1
	DefaultInUse           = 0
	DefaultIdle            = 1
)

Default database stats values

View Source
const (
	ContentTypeHeader     = "content-type"
	ContentEncodingHeader = "content-encoding"
	DeliveryModeHeader    = "delivery-mode"
	PriorityHeader        = "priority"
	CorrelationIDHeader   = "correlation-id"
	ReplyToHeader         = "reply-to"
	ExpirationHeader      = "expiration"
	MessageIDHeader       = "message-id"
	TypeHeader            = "type"
	UserIDHeader          = "user-id"
	AppIDHeader           = "app-id"
	ExchangeHeader        = "exchange"
	RoutingKeyHeader      = "routing-key"
)

AMQP message header constants

View Source
const (
	ApplicationJSONContentType = "application/json"
	TextPlainContentType       = "text/plain"
)

Content type constants

View Source
const (
	TestQueueName   = "test.queue"
	TestConsumerTag = "test-consumer"
)

Test constants

Variables

This section is empty.

Functions

func NewBindingDeclaration

func NewBindingDeclaration(queue, exchange, routingKey string) *messaging.BindingDeclaration

NewBindingDeclaration creates a binding declaration for testing.

func NewConsumerDeclaration

func NewConsumerDeclaration(queue, eventType string, handler messaging.MessageHandler) *messaging.ConsumerDeclaration

NewConsumerDeclaration creates a consumer declaration for testing.

func NewDatabaseWithData

func NewDatabaseWithData(data map[string][]any) *mocks.MockDatabase

NewDatabaseWithData creates a mock database pre-configured with data responses. The data map keys are SQL queries (can be partial matches) and values are the rows to return.

Example:

data := map[string][]any{
  "SELECT * FROM users": {
    []any{1, "John", "john@example.com"},
    []any{2, "Jane", "jane@example.com"},
  },
}
mockDB := fixtures.NewDatabaseWithData(data)

func NewDisconnectedMessagingClient

func NewDisconnectedMessagingClient() *mocks.MockMessagingClient

NewDisconnectedMessagingClient creates a mock messaging client that is not ready. This is useful for testing connection failure scenarios.

func NewErrorResult

func NewErrorResult(err error) sql.Result

NewErrorResult creates sql.Result that returns errors for testing error scenarios.

func NewExchangeDeclaration

func NewExchangeDeclaration(name, exchangeType string) *messaging.ExchangeDeclaration

NewExchangeDeclaration creates a standard exchange declaration for testing.

func NewFailedTransaction

func NewFailedTransaction(commitErr error) *mocks.MockTx

NewFailedTransaction creates a mock transaction that fails on commit.

func NewFailingAMQPClient

func NewFailingAMQPClient() *mocks.MockAMQPClient

NewFailingAMQPClient creates a mock AMQP client that fails infrastructure operations.

func NewFailingDatabase

func NewFailingDatabase(err error) *mocks.MockDatabase

NewFailingDatabase creates a mock database that fails health checks and operations. This is useful for testing error scenarios and failure handling.

func NewFailingMessagingClient

func NewFailingMessagingClient(failAfter int) *mocks.MockMessagingClient

NewFailingMessagingClient creates a mock messaging client that fails operations after a specified number of successful operations. This is useful for testing retry logic and error handling.

func NewFailingRegistry

func NewFailingRegistry() *mocks.MockRegistry

NewFailingRegistry creates a mock registry that fails infrastructure operations.

func NewHealthyDatabase

func NewHealthyDatabase() *mocks.MockDatabase

NewHealthyDatabase creates a mock database that responds positively to health checks and basic operations. This is useful for testing happy path scenarios.

func NewJSONDelivery

func NewJSONDelivery(jsonBody []byte) amqp.Delivery

NewJSONDelivery creates an AMQP delivery with JSON content type.

func NewMessageSimulator

func NewMessageSimulator(messages ...[]byte) *mocks.MockMessagingClient

NewMessageSimulator creates a mock messaging client that can simulate incoming messages. This is useful for testing consumer behavior and message processing.

func NewMockDelivery

func NewMockDelivery(body []byte, headers map[string]any) amqp.Delivery

NewMockDelivery creates an AMQP delivery for testing message handlers. This is useful when you need to simulate incoming messages with specific content.

Example:

delivery := fixtures.NewMockDelivery([]byte(`{"event": "user.created"}`), map[string]any{
  fixtures.ContentTypeHeader: fixtures.ApplicationJSONContentType,
  fixtures.RoutingKeyHeader:  "user.created",
})

func NewMockResult

func NewMockResult(lastInsertID, rowsAffected int64) sql.Result

NewMockResult creates sql.Result for testing Exec operations. This is useful when you need to simulate INSERT, UPDATE, or DELETE operations.

Example:

result := fixtures.NewMockResult(1, 5) // lastInsertId=1, rowsAffected=5

func NewMockRows

func NewMockRows(columns []string, rows [][]any) *sql.Rows

NewMockRows creates sql.Rows for testing with the provided columns and data. This is useful when you need to return specific data from Query operations.

Example:

rows := fixtures.NewMockRows(
  []string{"id", "name", "email"},
  [][]any{
    {1, "John", "john@example.com"},
    {2, "Jane", "jane@example.com"},
  },
)

func NewMongoDatabase

func NewMongoDatabase() *mocks.MockDatabase

NewMongoDatabase creates a mock database that behaves like MongoDB (via the adapter).

func NewOracleDatabase

func NewOracleDatabase() *mocks.MockDatabase

NewOracleDatabase creates a mock database that behaves like Oracle.

func NewPostgreSQLDatabase

func NewPostgreSQLDatabase() *mocks.MockDatabase

NewPostgreSQLDatabase creates a mock database that behaves like PostgreSQL.

func NewPublisherDeclaration

func NewPublisherDeclaration(exchange, routingKey, eventType string) *messaging.PublisherDeclaration

NewPublisherDeclaration creates a publisher declaration for testing.

func NewQueueDeclaration

func NewQueueDeclaration(name string) *messaging.QueueDeclaration

NewQueueDeclaration creates a standard queue declaration for testing.

func NewReadOnlyDatabase

func NewReadOnlyDatabase() *mocks.MockDatabase

NewReadOnlyDatabase creates a mock database that only allows read operations. Write operations will fail with an appropriate error.

func NewSuccessfulTransaction

func NewSuccessfulTransaction() *mocks.MockTx

NewSuccessfulTransaction creates a mock transaction that commits successfully.

func NewTextDelivery

func NewTextDelivery(textBody []byte) amqp.Delivery

NewTextDelivery creates an AMQP delivery with plain text content type.

func NewWorkingAMQPClient

func NewWorkingAMQPClient() *mocks.MockAMQPClient

NewWorkingAMQPClient creates a mock AMQP client that operates successfully.

func NewWorkingMessagingClient

func NewWorkingMessagingClient() *mocks.MockMessagingClient

NewWorkingMessagingClient creates a mock messaging client that operates successfully. This is useful for testing happy path scenarios.

func NewWorkingRegistry

func NewWorkingRegistry() *mocks.MockRegistry

NewWorkingRegistry creates a mock registry that operates successfully.

Types

This section is empty.

Jump to

Keyboard shortcuts

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