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 ¶
const BaggageKey = "coremart.test"
BaggageKey is the one baggage key InstallTelemetry allowlists, so a leak is observable.
Variables ¶
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.
Types ¶
type HeaderServer ¶
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