dispatchtest

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 12 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 dispatchtest holds what every host of dispatch.Dispatcher tests against: the exported contract (Contract), a recording fake for core tests (Fake), and a minimal HTTP host for tests that talk to an httptest server (HTTPHost).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnthropicAuth

func AnthropicAuth(key, scheme string) http.Header

AnthropicAuth is the header an Anthropic-dialect key goes in: x-api-key, or a bearer token when scheme is "bearer" (gateways).

func BearerAuth

func BearerAuth(key string) http.Header

BearerAuth is Authorization: Bearer key.

func Contract

func Contract(t *testing.T, newH NewHarness)

Contract is what every host's Dispatcher must satisfy. A change in context-guru that breaks it fails here first, before it reaches a host.

Types

type Fake

type Fake struct {
	Respond func(dispatch.Request) (dispatch.Response, error)
	Prices  func(endpoint, model string, promptTokens int64) (dispatch.Price, bool)
	// contains filtered or unexported fields
}

Fake is a recording Dispatcher for core tests. Respond answers every Do on a pinned ref; Prices answers Price (nil: nothing is priced).

func NewFake

func NewFake(respond func(dispatch.Request) (dispatch.Response, error)) *Fake

func (*Fake) Do

func (*Fake) Pin

func (f *Fake) Pin() dispatch.Ref

Pin issues a ref that Do answers until Release.

func (*Fake) Price

func (f *Fake) Price(_ context.Context, endpoint, model string, promptTokens int64) (dispatch.Price, bool)

func (*Fake) Release

func (f *Fake) Release(ref dispatch.Ref)

func (*Fake) Sent

func (f *Fake) Sent() []dispatch.Request

Sent returns copies of every request Do accepted, in order.

type HTTPHost

type HTTPHost struct {
	// contains filtered or unexported fields
}

HTTPHost is the smallest real host: it sends to the targets pinned on it, with the headers pinned with them. For tests (and live test tools) that talk to an httptest server or a real endpoint. It holds credentials in the clear and prices nothing — a production host masks what it holds and owns a rate table.

func HTTP

func HTTP(base string, auth http.Header) (*HTTPHost, dispatch.Ref)

HTTP is NewHTTPHost plus one pinned target: the common test shape.

func NewHTTPHost

func NewHTTPHost() *HTTPHost

NewHTTPHost returns an empty host whose client never follows a redirect.

func (*HTTPHost) Do

func (*HTTPHost) Pin

func (h *HTTPHost) Pin(base string, auth http.Header) dispatch.Ref

Pin holds base and auth until Release, and returns their Ref.

func (*HTTPHost) Price

Price knows no model: a test that needs rates uses Fake.

func (*HTTPHost) Release

func (h *HTTPHost) Release(ref dispatch.Ref)

type Harness

type Harness struct {
	D    dispatch.Dispatcher
	Hold func(reqHeaders http.Header) dispatch.Ref
}

Harness is one host's Dispatcher under test, plus the host-side hook that captures a credential for the upstream under test. Hold receives the request headers the host captures it from and returns the Ref it issued.

type NewHarness

type NewHarness func(t *testing.T, upstreamURL string) Harness

NewHarness builds a host whose held targets point at upstreamURL (scheme://host, no path).

Jump to

Keyboard shortcuts

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