testutil

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGinTestRouter

func NewGinTestRouter(middlewares ...gin.HandlerFunc) *gin.Engine

NewGinTestRouter creates an engine with the given middlewares in test mode.

func NewSampledTraceparent

func NewSampledTraceparent(traceIDHex, parentSpanIDHex string) string

NewSampledTraceparent creates a standard W3C traceparent string with sampled=01.

func NewUnsampledTraceparent

func NewUnsampledTraceparent(traceIDHex, parentSpanIDHex string) string

NewUnsampledTraceparent creates a standard W3C traceparent string with sampled=00.

func OperationEventCaptureMiddleware

func OperationEventCaptureMiddleware(target *OperationSnapshotWrapper) gin.HandlerFunc

OperationEventCaptureMiddleware captures the OperationEvent snapshot on terminal emit.

Types

type DownstreamRecorder

type DownstreamRecorder struct {
	Server          *httptest.Server
	ReceivedHeaders []http.Header
	// contains filtered or unexported fields
}

DownstreamRecorder creates an httptest.Server that records all incoming HTTP headers.

func NewDownstreamRecorder

func NewDownstreamRecorder() *DownstreamRecorder

NewDownstreamRecorder initializes and starts an httptest.Server recording headers.

func NewDownstreamRecorderWithBody

func NewDownstreamRecorderWithBody(body string) *DownstreamRecorder

NewDownstreamRecorderWithBody initializes a recorder whose server responds with the given fixed body (Content-Type: application/json, status 200) on every request. Use this instead of mutating Server.Config.Handler after construction.

func (*DownstreamRecorder) CallCount

func (d *DownstreamRecorder) CallCount() int

CallCount returns the total number of requests received by the downstream server.

func (*DownstreamRecorder) Close

func (d *DownstreamRecorder) Close()

Close shuts down the recorded server.

func (*DownstreamRecorder) LastHeader

func (d *DownstreamRecorder) LastHeader() http.Header

LastHeader returns the most recently received request header, if any.

type GRPCBufConnHarness

type GRPCBufConnHarness struct {
	Listener *bufconn.Listener
	Server   *grpc.Server
}

GRPCBufConnHarness provides an in-memory bufconn listener and dialer for gRPC testing. Since bufconn listener is synchronous and in-memory, Dial() connects via the pre-allocated listener buffer without needing an asynchronous network readiness handshake.

func NewGRPCBufConnHarness

func NewGRPCBufConnHarness(serverOpts ...grpc.ServerOption) *GRPCBufConnHarness

NewGRPCBufConnHarness creates a new bufconn listener and gRPC server.

func (*GRPCBufConnHarness) Close

func (g *GRPCBufConnHarness) Close()

Close cleans up the server and listener.

func (*GRPCBufConnHarness) Dial

func (g *GRPCBufConnHarness) Dial(ctx context.Context, dialOpts ...grpc.DialOption) (*grpc.ClientConn, error)

Dial creates a client connection to the in-memory bufconn server.

func (*GRPCBufConnHarness) Serve

func (g *GRPCBufConnHarness) Serve()

Serve starts the gRPC server on the bufconn listener in a background goroutine. bufconn buffers in-memory, so client connections can immediately dial without readiness waiting.

type Harness

type Harness struct {
	Exporter      *tracetest.InMemoryExporter
	Provider      *sdktrace.TracerProvider
	DecoyExporter *tracetest.InMemoryExporter
	DecoyProvider *sdktrace.TracerProvider
	Propagator    propagation.TextMapPropagator
	Shutdown      func(context.Context) error

	RecordedLogs []RecordedLog
	// contains filtered or unexported fields
}

Harness holds test instrumentation components for verifying OpenTelemetry trace participation.

func NewTestHarness

func NewTestHarness() *Harness

NewTestHarness creates a new shared test harness with ParentBased(NeverSample()) sampling and ParticipatingPropagator.

func (*Harness) LogEmitCount

func (h *Harness) LogEmitCount() int

LogEmitCount returns the number of log entries recorded.

func (*Harness) Logs

func (h *Harness) Logs() []RecordedLog

Logs returns a snapshot copy of recorded log entries.

func (*Harness) RecordLog

func (h *Harness) RecordLog(msg string, args ...any)

RecordLog appends an intercepted log entry to the harness.

type OperationSnapshotWrapper

type OperationSnapshotWrapper struct {
	Snapshot  operationevent.Snapshot
	EmitCount int
	// contains filtered or unexported fields
}

OperationSnapshotWrapper holds a captured OperationEvent snapshot and count.

func (*OperationSnapshotWrapper) Count

func (w *OperationSnapshotWrapper) Count() int

Count returns the emit count.

func (*OperationSnapshotWrapper) GetSnapshot

GetSnapshot returns a copy of the captured snapshot.

func (*OperationSnapshotWrapper) Record

Record captures an emitted snapshot.

type RecordedLog

type RecordedLog struct {
	Message string
	Args    []any
}

RecordedLog captures structured log entries emitted during testing.

Jump to

Keyboard shortcuts

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