Documentation
¶
Index ¶
- func NewGinTestRouter(middlewares ...gin.HandlerFunc) *gin.Engine
- func NewSampledTraceparent(traceIDHex, parentSpanIDHex string) string
- func NewUnsampledTraceparent(traceIDHex, parentSpanIDHex string) string
- func OperationEventCaptureMiddleware(target *OperationSnapshotWrapper) gin.HandlerFunc
- type DownstreamRecorder
- type GRPCBufConnHarness
- type Harness
- type OperationSnapshotWrapper
- type RecordedLog
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 ¶
NewSampledTraceparent creates a standard W3C traceparent string with sampled=01.
func NewUnsampledTraceparent ¶
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 ¶
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 ¶
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.
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 ¶
func (w *OperationSnapshotWrapper) GetSnapshot() operationevent.Snapshot
GetSnapshot returns a copy of the captured snapshot.
func (*OperationSnapshotWrapper) Record ¶
func (w *OperationSnapshotWrapper) Record(s operationevent.Snapshot)
Record captures an emitted snapshot.
type RecordedLog ¶
RecordedLog captures structured log entries emitted during testing.