test

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 30 Imported by: 1 module, 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 test has a registry and a HTTP server of its API, for tests

Index

Constants

View Source
const Prefix = "/api"

Prefix is the path prefix for the API routes

Variables

This section is empty.

Functions

func NewRegistry

func NewRegistry(t *testing.T, providers []llm.Provider, opts ...registry.Opt) *registry.Registry

NewRegistry returns a registry, with the options, and the providers, each by its own name, such as its type, or fails the test. As the registry isn't stored, each test has a registry of its own.

func NewToolkit added in v0.6.0

func NewToolkit(t *testing.T) *toolkit.Toolkit

NewToolkit returns a toolkit for tests, with a memory namespace, which has no tools, and a weather namespace, which has the current and forecast tools, or fails the test

Types

type AgentStore added in v0.6.0

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

AgentStore is a store of agents in memory, by their names, which it lists in order of their names, for tests, whose serials are of the store, rather than of each agent, so an agent which is deleted, and created again, doesn't have a serial it had

func NewAgentStore added in v0.6.0

func NewAgentStore() *AgentStore

NewAgentStore returns a store of agents in memory, which has none

func (*AgentStore) Create added in v0.6.0

func (m *AgentStore) Create(_ context.Context, meta schema.AgentMeta) (schema.Agent, error)

func (*AgentStore) Delete added in v0.6.0

func (m *AgentStore) Delete(_ context.Context, name string, serial uint64) error

func (*AgentStore) Get added in v0.6.0

func (m *AgentStore) Get(_ context.Context, name string) (schema.Agent, error)

func (*AgentStore) List added in v0.6.0

func (*AgentStore) Put added in v0.6.0

func (m *AgentStore) Put(_ context.Context, agent schema.Agent) (schema.Agent, error)

type Exchange

type Exchange struct {
	Method string
	Path   string

	// Pattern is the route pattern which matched the request, such as
	// "/api/llm/provider", or empty if no route matched
	Pattern string

	RequestHeader  http.Header
	RequestBody    []byte
	Status         int
	ResponseHeader http.Header
	ResponseBody   []byte
}

Exchange is a recorded request and response

func (Exchange) String

func (e Exchange) String() string

type Server

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

Server is a HTTP test server serving the llm registry API. Every request and response is recorded, and checked against the OpenAPI specification when the test ends.

func NewServer

func NewServer(t *testing.T, r *registry.Registry) *Server

NewServer starts a HTTP test server serving the llm registry API for the registry, and its broadcaster's API, which streams its events. When the test ends the server is closed, and every recorded exchange is checked against the OpenAPI specification.

func NewServerFunc

func NewServerFunc(t *testing.T, register func(*httprouter.Router) error) *Server

NewServerFunc starts a HTTP test server serving the API registered by the function. When the test ends the server is closed, and every recorded exchange is checked against the OpenAPI specification.

func (*Server) Do

func (s *Server) Do(t *testing.T, method, path string, body any) (int, []byte)

Do sends a request to the API with a JSON body, and returns the status code and response body. The path is relative to the API prefix, and may include a query string. A body which is a string or []byte is sent as-is, nil sends no body, and any other value is encoded as JSON.

func (*Server) DoWithContentType

func (s *Server) DoWithContentType(t *testing.T, method, path, contentType string, body any) (int, []byte)

DoWithContentType sends a request with the body as the content type, which is used as-is for a string or []byte body, and otherwise encoded as JSON. Returns the status code and the response body.

func (*Server) Exchanges

func (s *Server) Exchanges() []Exchange

Exchanges returns the recorded requests and responses

func (*Server) JSON

func (s *Server) JSON(t *testing.T, method, path string, body, v any) int

JSON sends a request to the API as Do does, and decodes a successful response body into v. Returns the status code.

func (*Server) Reset

func (s *Server) Reset()

Reset discards the recorded requests and responses

func (*Server) Spec

func (s *Server) Spec() *openapi.Spec

Spec returns the OpenAPI specification for the API

func (*Server) Verify

func (s *Server) Verify() []error

Verify checks every recorded exchange against the OpenAPI specification, and returns an error for each which does not conform

type SessionStore added in v0.6.0

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

SessionStore is a store of sessions in memory, whose identifiers are version 7 UUIDs, which are in the order the sessions are created, for tests. Its watchers are sent the events which Changed is called with, as changes which others made.

func NewSessionStore added in v0.6.0

func NewSessionStore() *SessionStore

NewSessionStore returns a store of sessions in memory, which has none

func (*SessionStore) Changed added in v0.6.0

func (m *SessionStore) Changed(event eventschema.Event) int

Changed sends the event to the watchers, as a change which others made, such as another server, and returns how many it was sent to

func (*SessionStore) Create added in v0.6.0

func (*SessionStore) Delete added in v0.6.0

func (m *SessionStore) Delete(_ context.Context, id uuid.UUID, serial uint64) error

func (*SessionStore) Get added in v0.6.0

func (*SessionStore) Len added in v0.6.0

func (m *SessionStore) Len() int

Len returns how many sessions there are

func (*SessionStore) List added in v0.6.0

func (*SessionStore) Put added in v0.6.0

func (m *SessionStore) Put(_ context.Context, session schema.Session) (schema.Session, error)

func (*SessionStore) Watch added in v0.6.0

func (m *SessionStore) Watch(ctx context.Context, ch chan<- eventschema.Event) (<-chan error, error)

Watch sends the events which Changed is called with to the channel, until the context is cancelled, when the returned channel is sent nil

Jump to

Keyboard shortcuts

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