Documentation
¶
Overview ¶
Package test has a registry and a HTTP server of its API, for tests
Index ¶
- Constants
- func NewRegistry(t *testing.T, providers []llm.Provider, opts ...registry.Opt) *registry.Registry
- type Exchange
- type Server
- func (s *Server) Do(t *testing.T, method, path string, body any) (int, []byte)
- func (s *Server) DoWithContentType(t *testing.T, method, path, contentType string, body any) (int, []byte)
- func (s *Server) Exchanges() []Exchange
- func (s *Server) JSON(t *testing.T, method, path string, body, v any) int
- func (s *Server) Reset()
- func (s *Server) Spec() *openapi.Spec
- func (s *Server) Verify() []error
Constants ¶
const Prefix = "/api"
Prefix is the path prefix for the API routes
Variables ¶
This section is empty.
Functions ¶
func NewRegistry ¶
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
type Server ¶
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 ¶
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 ¶
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 ¶
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) JSON ¶
JSON sends a request to the API as Do does, and decodes a successful response body into v. Returns the status code.