Documentation
¶
Overview ¶
Package testbench hosts the mock services used by the integration suites.
Index ¶
- Constants
- func Fail(w http.ResponseWriter, r *http.Request, status int, message string, ...)
- func NormalizeMethod(next http.Handler) http.Handler
- func PartitionKeyFromContext(ctx context.Context) (string, bool)
- func PartitionRouter(inner http.Handler) http.Handler
- func RequestIDFromContext(ctx context.Context) string
- func Serve(ctx context.Context, reg *Registry, log *slog.Logger) error
- func ServiceLogger(ctx context.Context) *slog.Logger
- func WriteJSON(w http.ResponseWriter, r *http.Request, status int, value any)
- type Partitioned
- type Registry
- type Service
- type TLSService
Constants ¶
const PartitionByBlock = "block"
PartitionByBlock identifies the framework-guaranteed block partition.
const RequestIDHeader = "X-Request-Id"
RequestIDHeader carries a correlation id in and out of every mock service. A caller that sets it has its own value echoed back and logged, so a suite step can tie an assertion to the exact request the testbench saw; otherwise one is generated here.
Variables ¶
This section is empty.
Functions ¶
func Fail ¶
Fail writes an error response and logs why, with this request's service, correlation id, and partition already attached. Prefer it over http.Error in a mock service: the access line records the status either way, but only the caller knows the structured detail behind it, and that detail is what turns a 400 in a CI log into an actionable one.
func NormalizeMethod ¶
NormalizeMethod normalizes the request method before dispatching to a handler that uses method-qualified ServeMux patterns.
func PartitionKeyFromContext ¶
PartitionKeyFromContext returns the block key set by PartitionRouter.
func PartitionRouter ¶
PartitionRouter validates and strips the leading /<block> path segment from every request, making the block key available to the wrapped handler via PartitionKeyFromContext. Any Stateful service that partitions by PartitionByBlock routes its mux through this so every hosted route is addressed as /<block>/rest-of-path.
func RequestIDFromContext ¶
RequestIDFromContext returns the correlation id assigned to this request, for a service that wants to name it in its own log lines.
func Serve ¶
Serve starts every registered service on its own port and blocks until ctx is cancelled.
func ServiceLogger ¶
ServiceLogger returns a logger already tagged with this request's service, correlation id, and partition, so a handler logs consistently without restating them.
Types ¶
type Partitioned ¶
type Partitioned interface {
// PartitionKey returns the name of the partition guarantee.
PartitionKey() string
}
Partitioned identifies a stateful service whose state is isolated by a framework-guaranteed key.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the single table of hosted services.
type Service ¶
type Service interface {
// Name identifies the service.
Name() string
// Port returns the container port on which the service listens.
Port() int
// Handler returns the service HTTP handler.
Handler() http.Handler
// Stateful reports whether the service retains state between requests.
Stateful() bool
}
Service is a mock service hosted by the testbench.
type TLSService ¶
type TLSService interface {
// TLSConfig returns the server TLS configuration. It must carry a certificate.
TLSConfig() *tls.Config
}
TLSService is implemented by a Service that serves HTTPS rather than plain HTTP on its port.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
testbench
command
Command testbench runs the mock services used by the integration suites.
|
Command testbench runs the mock services used by the integration suites. |
|
services
|
|
|
agentcard
Package agentcard provides a block-partitioned A2A Agent Card upstream with deterministic failure modes and a per-scope request counter.
|
Package agentcard provides a block-partitioned A2A Agent Card upstream with deterministic failure modes and a per-scope request counter. |
|
analytics
Package analytics provides a partitioned Moesif-compatible analytics collector for integration tests.
|
Package analytics provides a partitioned Moesif-compatible analytics collector for integration tests. |
|
backend
Package backend provides the stateless upstream used by integration tests.
|
Package backend provides the stateless upstream used by integration tests. |
|
bedrock
Package bedrock provides a deterministic AWS Bedrock ApplyGuardrail-compatible service.
|
Package bedrock provides a deterministic AWS Bedrock ApplyGuardrail-compatible service. |
|
capture
Package capture provides a partitioned upstream that remembers the last request it received per path.
|
Package capture provides a partitioned upstream that remembers the last request it received per path. |
|
contentsafety
Package contentsafety provides a deterministic Azure AI Content Safety-compatible service.
|
Package contentsafety provides a deterministic Azure AI Content Safety-compatible service. |
|
echo
Package echo provides HTTP reflection endpoints for integration tests.
|
Package echo provides HTTP reflection endpoints for integration tests. |
|
embeddings
Package embeddings provides a deterministic OpenAI-compatible embedding service for integration tests.
|
Package embeddings provides a deterministic OpenAI-compatible embedding service for integration tests. |
|
graphqlbackend
Package graphqlbackend provides a GraphQL-shaped upstream that echoes the request body back verbatim, unwrapped, as the response body.
|
Package graphqlbackend provides a GraphQL-shaped upstream that echoes the request body back verbatim, unwrapped, as the response body. |
|
guardian
Package guardian provides a deterministic content-safety model for the guardrail policies that ask an OpenAI-compatible chat model for a verdict: NeMo Guard Content Safety and Granite Guardian.
|
Package guardian provides a deterministic content-safety model for the guardrail policies that ask an OpenAI-compatible chat model for a verdict: NeMo Guard Content Safety and Granite Guardian. |
|
interceptor
Package interceptor provides a stateless request/response interceptor upstream.
|
Package interceptor provides a stateless request/response interceptor upstream. |
|
jev
Package jev provides a partitioned TypeSafe Jev System One API with deterministic answers, failure modes and a per-partition request log.
|
Package jev provides a partitioned TypeSafe Jev System One API with deterministic answers, failure modes and a per-partition request log. |
|
jwks
Package jwks serves a JWKS and signs test tokens on demand.
|
Package jwks serves a JWKS and signs test tokens on demand. |
|
mcp
Package mcp provides a stateless streamable-HTTP MCP server for integration tests.
|
Package mcp provides a stateless streamable-HTTP MCP server for integration tests. |
|
mcpscripted
Package mcpscripted provides an MCP server whose tool results a scenario scripts, so a policy that reads tool results can be tested on every shape a server may send.
|
Package mcpscripted provides an MCP server whose tool results a scenario scripts, so a policy that reads tool results can be tested on every shape a server may send. |
|
oauth2
Package oauth2 provides the partitioned OAuth2 identity provider used by gateway tests.
|
Package oauth2 provides the partitioned OAuth2 identity provider used by gateway tests. |
|
oidc
Package oidc provides an OpenID Connect identity provider for the API Portal's IDP mode.
|
Package oidc provides an OpenID Connect identity provider for the API Portal's IDP mode. |
|
opa
Package opa provides a deterministic Open Policy Agent (OPA) data API for the opa-policy integration tests.
|
Package opa provides a deterministic Open Policy Agent (OPA) data API for the opa-policy integration tests. |
|
openai
Package openai provides a deterministic, stateless mock upstream for several LLM providers.
|
Package openai provides a deterministic, stateless mock upstream for several LLM providers. |
|
tlsbackend
Package tlsbackend provides HTTPS backends that require a client certificate and report the subject of the one they received, for the gateway's outbound mutual TLS.
|
Package tlsbackend provides HTTPS backends that require a client certificate and report the subject of the one they received, for the gateway's outbound mutual TLS. |
|
webhook
Package webhook provides a block-partitioned HTTP receiver for API Portal deliveries.
|
Package webhook provides a block-partitioned HTTP receiver for API Portal deliveries. |