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 ¶
- func BuildRouteFDS(tb testing.TB, fileOpts *descriptorpb.FileOptions, ...) []byte
- func Decorations() decorate.Decorations
- func EmptyMessage(name string) *descriptorpb.DescriptorProto
- func ErrPipeline(err error) *mocks.MockPipeline[string, string]
- func ErrWorkflow(err error) *mocks.MockWorkflow[string, string]
- func JSONAPIAnnotations(tb testing.TB) protoreflect.FileDescriptor
- func Method(name, input, output string, opts *descriptorpb.MethodOptions) *descriptorpb.MethodDescriptorProto
- func Must[T any](v T, err error) T
- func NopLogger() interfaces.Logger
- func NopMetrics() interfaces.Metrics
- func NopTracer() interfaces.Tracer
- func PanicPipeline() *mocks.MockPipeline[string, string]
- func PanicWorkflow() *mocks.MockWorkflow[string, string]
- func PassPipeline() *mocks.MockPipeline[string, string]
- func PassWorkflow() *mocks.MockWorkflow[string, string]
- func ResourceMessage(s JSONAPISetter, name, resType, single, collection string) *descriptorpb.DescriptorProto
- func SpyTracer(onSetAttribute func(key string, value any)) interfaces.Tracer
- func StubCircuitBreaker(open bool) *mocks.MockCircuitBreaker
- func StubClientStream(ctx context.Context, sendErr error, recvErrs ...error) grpc.ClientStream
- func StubPipeline(exec func(ctx context.Context, in string) (string, error)) *mocks.MockPipeline[string, string]
- func StubRateLimiter(allowed bool) *mocks.MockRateLimiter
- func StubRetrier(failUntil int, alwaysFail bool) (retrier *mocks.MockRetrier, attempts func() int)
- func StubService(getErr error, panicOnGet bool) *mocks.MockService[TestEntity, TestParams, string]
- func StubStore() *mocks.MockStore[TestEntity, TestParams, string]
- func StubWorkflow(exec func(ctx context.Context, in string) (string, error)) *mocks.MockWorkflow[string, string]
- type JSONAPISetter
- type SpyLogger
- type TestEntity
- type TestParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildRouteFDS ¶ added in v0.0.22
func BuildRouteFDS( tb testing.TB, fileOpts *descriptorpb.FileOptions, messages []*descriptorpb.DescriptorProto, methods []*descriptorpb.MethodDescriptorProto, ) []byte
BuildRouteFDS assembles a marshaled, self-contained FileDescriptorSet from the synthetic jsonapi annotations file + google/api + a single test.v1 service file (messages + methods), the exact input openapi.BuildRouteTable consumes.
func Decorations ¶ added in v0.0.14
func Decorations() decorate.Decorations
Decorations returns the Decorations that resolves every component and operation to no layers, for tests that build a base of any tier undecorated (recovery only): fixtures.Must(service.NewBase[C](fixtures.Decorations(), "test")).
func EmptyMessage ¶ added in v0.0.22
func EmptyMessage(name string) *descriptorpb.DescriptorProto
EmptyMessage is a no-field response message (e.g. a delete response) carrying no (jsonapi.v1.resource) option.
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 JSONAPIAnnotations ¶ added in v0.0.22
func JSONAPIAnnotations(tb testing.TB) protoreflect.FileDescriptor
JSONAPIAnnotations builds the protoreflect.FileDescriptor for a hand-authored jsonapi/v1/annotations.proto — the three messages (JsonApiService / JsonApiResource / JsonApiOperation) and their three extends (FileOptions / MessageOptions / MethodOptions, all field 50001) — resolved against the linked descriptor.proto. It lets the tests set the jsonapi extension VALUES on synthetic options via dynamicpb without depending on the generated stubs.
func Method ¶ added in v0.0.22
func Method( name, input, output string, opts *descriptorpb.MethodOptions, ) *descriptorpb.MethodDescriptorProto
Method builds a MethodDescriptorProto wiring input/output messages (by unqualified name in package test.v1) and the given http/operation options.
func Must ¶ added in v0.0.10
Must returns v, panicking when err is non-nil: a test's wiring of a constructor that returns (T, error), such as a base built from decorations, fails loudly.
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 ResourceMessage ¶ added in v0.0.22
func ResourceMessage( s JSONAPISetter, name, resType, single, collection string, ) *descriptorpb.DescriptorProto
ResourceMessage is a response message carrying a (jsonapi.v1.resource) option.
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 ¶
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.
Types ¶
type JSONAPISetter ¶ added in v0.0.22
type JSONAPISetter struct {
// contains filtered or unexported fields
}
JSONAPISetter carries the dynamic extension types + message descriptors decoded from the synthetic jsonapi annotations file, so a test can stamp jsonapi.v1.service / .resource / .operation onto descriptorpb options without the generated stubs.
func NewJSONAPISetter ¶ added in v0.0.22
func NewJSONAPISetter(tb testing.TB, fd protoreflect.FileDescriptor) JSONAPISetter
NewJSONAPISetter decodes the extension + message descriptors from the synthetic jsonapi annotations file into a JSONAPISetter.
func (JSONAPISetter) FileOptsWithService ¶ added in v0.0.22
func (s JSONAPISetter) FileOptsWithService() *descriptorpb.FileOptions
FileOptsWithService returns FileOptions carrying (jsonapi.v1.service) for the testsvc service at /api/v1.
func (JSONAPISetter) MethodOpts ¶ added in v0.0.22
func (s JSONAPISetter) MethodOpts( verb, path string, action bool, additional ...[2]string, ) *descriptorpb.MethodOptions
MethodOpts returns MethodOptions carrying the google.api.http binding (verb + path, plus any additional bindings) and, when action is true, the (jsonapi.v1.operation){action:true} marker.
func (JSONAPISetter) MsgOptsWithResource ¶ added in v0.0.22
func (s JSONAPISetter) MsgOptsWithResource( resType, single, collection string, ) *descriptorpb.MessageOptions
MsgOptsWithResource returns MessageOptions carrying (jsonapi.v1.resource) with the given type/single/collection keys (empty keys are omitted).
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 (Run) and the routing-sink suite (RunRouting) a consumer runs against its own store and sink over real infrastructure; the engine runs them against the postgres outbox-store kind.
|
Package outboxtest is the reusable OutboxStore conformance suite (Run) and the routing-sink suite (RunRouting) a consumer runs against its own store and sink over real infrastructure; the engine runs them against the postgres outbox-store kind. |
|
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. |