httpclienttest

package
v0.0.0-...-d09923a Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: LGPL-2.1 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httpclienttest holds test helpers for code that calls out through the shared HTTP client: an in-memory tracer, a traced request context, and a server that records headers. Import it from _test files only.

Index

Constants

View Source
const BaggageKey = "coremart.test"

BaggageKey is the one baggage key InstallTelemetry allowlists, so a leak is observable.

Variables

View Source
var TelemetryHeaders = []string{"traceparent", "tracestate", "baggage", telemetry.HeaderIdempotencyId}

TelemetryHeaders are the headers only an allowlisted host may receive.

Functions

func InstallTelemetry

func InstallTelemetry(t testing.TB) *tracetest.SpanRecorder

InstallTelemetry sets the global tracer provider and propagator for the test and restores the previous ones afterwards. Tests using it must not run in parallel.

func NewClient

func NewClient(t testing.TB, logger logging.LoggerService, allowedHosts ...string) *client.HttpClient

NewClient builds the shared client as production does, with the given propagation allowlist.

func TracedContext

func TracedContext(t testing.TB) (context.Context, string)

TracedContext is a request context as ingress leaves it: an active span, an idempotency id and one allowlisted baggage member.

Types

type HeaderServer

type HeaderServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

HeaderServer is an httptest server that records the headers of every request it receives.

func NewHeaderServer

func NewHeaderServer(t testing.TB, handler http.HandlerFunc) *HeaderServer

func (*HeaderServer) AssertNoTelemetryHeaders

func (this *HeaderServer) AssertNoTelemetryHeaders(t testing.TB)

AssertNoTelemetryHeaders fails unless the server received at least one request and none of them carried a telemetry header.

func (*HeaderServer) HostPort

func (this *HeaderServer) HostPort(t testing.TB) string

HostPort is the server's "host:port", the exact allowlist entry for it alone.

func (*HeaderServer) Received

func (this *HeaderServer) Received() []http.Header

Jump to

Keyboard shortcuts

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