fixtures

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package fixtures provides thin, hand-written factories over the GENERATED gomock mocks in the sibling mocks package. It is the shared test-support layer: the mocks package stays generated-only (mock_*.go), and every configured double a test needs is built here from those generated mocks.

Why the factories take no *testing.T

The no-op doubles (NopLogger/NopMetrics/NopTracer) build their gomock controller from a no-op TestReporter, so callers get a ready no-op mock with zero ceremony — `fixtures.NopLogger()` drops in wherever `mocks.NopLogger{}` used to. Every method is registered AnyTimes, so an unmet/absent expectation can never fire and the controller never needs Finish().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrPipeline

func ErrPipeline(err error) *mocks.MockPipeline[string, string]

ErrPipeline returns a MockPipeline whose Execute returns ("", err).

func ErrWorkflow

func ErrWorkflow(err error) *mocks.MockWorkflow[string, string]

ErrWorkflow returns a MockWorkflow whose Execute returns ("", err).

func NopLogger

func NopLogger() interfaces.Logger

NopLogger returns a generated MockLogger whose every method is a no-op and whose With/WithContext return the same logger, for tests that must pass a logger but never assert on log output.

func NopMetrics

func NopMetrics() interfaces.Metrics

NopMetrics returns a generated MockMetrics whose Counter/Histogram/Gauge yield no-op sub-metrics, for tests that must pass a metrics provider but never assert on recorded values.

func NopTracer

func NopTracer() interfaces.Tracer

NopTracer returns a generated MockTracer whose spans discard every operation.

func PanicPipeline

func PanicPipeline() *mocks.MockPipeline[string, string]

PanicPipeline returns a MockPipeline whose Execute panics (for recovery-decorator tests).

func PanicWorkflow

func PanicWorkflow() *mocks.MockWorkflow[string, string]

PanicWorkflow returns a MockWorkflow whose Execute panics (for recovery-decorator tests).

func PassPipeline

func PassPipeline() *mocks.MockPipeline[string, string]

PassPipeline returns a MockPipeline that echoes "mock-output-"+input.

func PassWorkflow

func PassWorkflow() *mocks.MockWorkflow[string, string]

PassWorkflow returns a MockWorkflow that echoes "mock-workflow-output-"+input.

func SpyTracer

func SpyTracer(onSetAttribute func(key string, value any)) interfaces.Tracer

SpyTracer returns a generated MockTracer whose span forwards each SetAttribute call to onSetAttribute (nil = discard), for tests that assert which span attributes were set.

func StubCircuitBreaker

func StubCircuitBreaker(open bool) *mocks.MockCircuitBreaker

StubCircuitBreaker returns a generated MockCircuitBreaker: when open, Execute rejects without invoking the function; otherwise it runs the function.

func StubClientStream

func StubClientStream(
	ctx context.Context,
	sendErr error,
	recvErrs ...error,
) grpc.ClientStream

StubClientStream returns a generated MockClientStream for stream-interceptor tests: Context returns ctx (the caller's, never nil), SendMsg returns sendErr, and RecvMsg yields recvErrs in order then io.EOF. It replaces the former FakeClientStream.

func StubPipeline

func StubPipeline(
	exec func(ctx context.Context, in string) (string, error),
) *mocks.MockPipeline[string, string]

StubPipeline returns a generated MockPipeline whose Execute runs exec.

func StubRateLimiter

func StubRateLimiter(allowed bool) *mocks.MockRateLimiter

StubRateLimiter returns a generated MockRateLimiter: Allow reports allowed, and Wait returns an error when not allowed.

func StubRetrier

func StubRetrier(
	failUntil int,
	alwaysFail bool,
) (retrier *mocks.MockRetrier, attempts func() int)

StubRetrier returns a generated MockRetrier that fails the operation the first failUntil attempts (or always, capped at 3, when alwaysFail), plus a getter for the number of attempts made. It replaces the former FakeRetrier.

func StubService

func StubService(
	getErr error,
	panicOnGet bool,
) *mocks.MockService[TestEntity, TestParams, string]

StubService returns a generated MockService whose Get returns getErr (or panics when panicOnGet), and otherwise echoes a canned entity; List/Create/Update/Delete succeed. It replaces the former CustomMockService.

func StubStore

func StubStore() *mocks.MockStore[TestEntity, TestParams, string]

StubStore returns a generated MockStore backed by an in-memory map, so CRUD through it is observable end-to-end (Create then Get returns the entity, Delete drops it, Exists reflects presence). It replaces the former CustomMockStore.

func StubWorkflow

func StubWorkflow(
	exec func(ctx context.Context, in string) (string, error),
) *mocks.MockWorkflow[string, string]

StubWorkflow returns a generated MockWorkflow whose Execute runs exec.

Types

type SpyLogger

type SpyLogger struct {
	// MockLogger is the embedded generated mock whose expectations back the spy.
	*mocks.MockLogger
	// ChildDebugCalls records Debug messages logged on the WithContext child loggers,
	// so a test can assert the child actually logged (e.g. an observability decorator
	// that binds WithContext(ctx) for trace correlation and logs at Debug).
	ChildDebugCalls *[]string
	// ChildInfoCalls records Info messages logged on the WithContext child loggers.
	ChildInfoCalls *[]string
	// ChildWarnCalls records Warn messages logged on the WithContext child loggers.
	ChildWarnCalls *[]string
	// ChildErrorCalls records Error messages logged on the WithContext child loggers.
	ChildErrorCalls *[]string

	// DebugCalls records Debug messages logged directly on this logger.
	DebugCalls []string
	// InfoCalls records Info messages logged directly on this logger.
	InfoCalls []string
	// WarnCalls records Warn messages logged directly on this logger.
	WarnCalls []string
	// ErrorCalls records Error messages logged directly on this logger.
	ErrorCalls []string
	// ContextUsed is true when this logger was created by a WithContext call.
	ContextUsed bool
	// contains filtered or unexported fields
}

SpyLogger records log calls made through an embedded generated MockLogger, for tests that assert which messages were logged — directly and through WithContext child loggers. It replaces the former hand-rolled mocks.SpyLogger.

func NewSpyLogger

func NewSpyLogger() *SpyLogger

NewSpyLogger returns a SpyLogger that records log calls through a generated MockLogger, with WithContext yielding a recording child.

type TestEntity

type TestEntity struct {
	// ID is the entity identifier.
	ID string
	// Name is a human-readable label.
	Name string
}

TestEntity is a minimal domain entity for exercising repository and service operations through MockStore/MockService generic instantiations.

type TestParams

type TestParams struct{}

TestParams is a query-parameter type for testing List operations.

Directories

Path Synopsis
dbtest
cassandra
Package cassandra provides a testcontainers-based Apache Cassandra 5 instance for integration tests.
Package cassandra provides a testcontainers-based Apache Cassandra 5 instance for integration tests.
elasticmq
Package elasticmq provides a testcontainers-based ElasticMQ (SQS-compatible) instance for integration tests.
Package elasticmq provides a testcontainers-based ElasticMQ (SQS-compatible) instance for integration tests.
minio
Package minio provides a testcontainers-based MinIO instance for integration tests.
Package minio provides a testcontainers-based MinIO instance for integration tests.
postgres
Package postgres provides a generic testcontainers-based PostgreSQL database for integration tests.
Package postgres provides a generic testcontainers-based PostgreSQL database for integration tests.
redis
Package redis provides a testcontainers-based Redis instance for integration tests.
Package redis provides a testcontainers-based Redis instance for integration tests.
Package e2ekit is the gen-free shared test-kit for endpoint E2E + telemetry suites.
Package e2ekit is the gen-free shared test-kit for endpoint E2E + telemetry suites.
Package outboxtest is the reusable OutboxStore conformance suite plus a reference database/sql Postgres store it is proven against.
Package outboxtest is the reusable OutboxStore conformance suite plus a reference database/sql Postgres store it is proven against.
Package store (testutil) provides a interfaces.Store implementation that supports call counting and error injection for use in tests.
Package store (testutil) provides a interfaces.Store implementation that supports call counting and error injection for use in tests.
Package suite provides test suite constructors for unit and integration tests.
Package suite provides test suite constructors for unit and integration tests.
base
Package base provides the base test suite with shared utilities.
Package base provides the base test suite with shared utilities.

Jump to

Keyboard shortcuts

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