test

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 20 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.

Types

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. 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

Jump to

Keyboard shortcuts

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