testutil

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LoopbackHost        = netutil.LoopbackHost
	LoopbackDynamicAddr = netutil.LoopbackDynamicAddr
	LoopbackNoProxy     = netutil.LoopbackNoProxy
)

Variables

This section is empty.

Functions

func IsLoopbackUnavailable added in v0.2.1

func IsLoopbackUnavailable(err error) bool

func ListenLoopback added in v0.2.1

func ListenLoopback(t testing.TB) net.Listener

func NewLoopbackHTTPServer added in v0.2.1

func NewLoopbackHTTPServer(t testing.TB, handler http.Handler) *httptest.Server

func SkipIfLoopbackUnavailable added in v0.2.1

func SkipIfLoopbackUnavailable(t testing.TB, err error)

Types

type MockLLMServer

type MockLLMServer struct {
	Server    *httptest.Server
	Responses []MockResponse
	Requests  []MockRequest
	// contains filtered or unexported fields
}

MockLLMServer provides a configurable mock LLM API server for testing.

func NewMockLLMServer

func NewMockLLMServer(t *testing.T, responses ...MockResponse) *MockLLMServer

NewMockLLMServer creates a mock server that returns canned responses in order.

func (*MockLLMServer) ContainsString

func (m *MockLLMServer) ContainsString(s string) bool

ContainsString checks if any request body contains the given string.

func (*MockLLMServer) LastRequest

func (m *MockLLMServer) LastRequest() MockRequest

LastRequest returns the most recent request body.

func (*MockLLMServer) RequestCount

func (m *MockLLMServer) RequestCount() int

RequestCount returns how many requests were made.

func (*MockLLMServer) URL

func (m *MockLLMServer) URL() string

URL returns the base URL of the mock server.

type MockRequest

type MockRequest struct {
	Method string
	Path   string
	Body   map[string]interface{}
}

MockRequest records a request made to the mock server.

type MockResponse

type MockResponse struct {
	Content    string
	ToolUse    []ToolUseBlock
	StopReason string
	StatusCode int
}

MockResponse defines a canned response from the mock LLM.

func ErrorResponse

func ErrorResponse(statusCode int) MockResponse

ErrorResponse creates a mock error response.

func SimpleTextResponse

func SimpleTextResponse(text string) MockResponse

SimpleTextResponse creates a mock response with just text content.

func ToolUseResponse

func ToolUseResponse(toolName string, input map[string]interface{}) MockResponse

ToolUseResponse creates a mock response that calls a tool.

type ToolUseBlock

type ToolUseBlock struct {
	ID    string
	Name  string
	Input map[string]interface{}
}

ToolUseBlock represents a tool call in the response.

Jump to

Keyboard shortcuts

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