Documentation
¶
Overview ¶
Package server_validate provides a mock HTTP provider server that speaks OpenAI, Anthropic, and Google response formats for testing purposes.
A VirtualServer acts as a deterministic "virtual model" — scenario responses are pre-configured and returned without any real model calls. It is used by the virtualmodel test framework to exercise the gateway's protocol transform pipeline end-to-end.
Use VirtualClient (client.go) to send requests to the server and inspect parsed responses. A bound client is obtained via vs.Client().
Index ¶
- Constants
- type APIStyle
- type MockResponseBuilder
- type ParsedResponse
- type Scenario
- type VirtualClient
- func (vc *VirtualClient) SendAnthropicV1(t *testing.T, s Scenario, streaming bool) *ParsedResponse
- func (vc *VirtualClient) SendAnthropicV1Model(t *testing.T, modelID string, streaming bool) *ParsedResponse
- func (vc *VirtualClient) SendGoogle(t *testing.T, s Scenario, streaming bool) *ParsedResponse
- func (vc *VirtualClient) SendOpenAIChat(t *testing.T, s Scenario, streaming bool) *ParsedResponse
- func (vc *VirtualClient) SendOpenAIChatModel(t *testing.T, modelID string, streaming bool) *ParsedResponse
- func (vc *VirtualClient) SendOpenAIResponses(t *testing.T, s Scenario, streaming bool) *ParsedResponse
- func (vc *VirtualClient) WithServer(vs *VirtualServer) *VirtualClient
- type VirtualServer
Constants ¶
const ( StyleOpenAI = protocol.APIStyleOpenAI StyleAnthropic = protocol.APIStyleAnthropic StyleGoogle = protocol.APIStyleGoogle )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockResponseBuilder ¶
type MockResponseBuilder struct {
// NonStream returns the HTTP status code and response body bytes.
NonStream func() (statusCode int, body []byte)
// Stream returns the SSE event lines (each line is "data: ..." or "event: ...").
Stream func() []string
}
MockResponseBuilder defines how a virtual server should respond for one provider style.
type ParsedResponse ¶
type ParsedResponse struct {
HTTPStatus int
IsStreaming bool
StreamEvents []string
RawBody []byte
// Parsed semantics (populated from RawBody or StreamEvents)
sse.ParsedResult
}
ParsedResponse is the result of a request sent to a virtual server. It wraps sse.ParsedResult with HTTP-layer fields.
type Scenario ¶
type Scenario struct {
Name string
Description string
Tags []string
// MockResponses keyed by provider APIStyle ("openai", "anthropic", "google").
MockResponses map[APIStyle]MockResponseBuilder
}
Scenario is a named test scenario describing what the mock provider returns.
type VirtualClient ¶
type VirtualClient struct {
// contains filtered or unexported fields
}
VirtualClient sends provider-native HTTP requests for testing. It can operate standalone (pointed at any URL) or bound to a VirtualServer (which auto-registers scenarios before each request).
func NewVirtualClient ¶
func NewVirtualClient(baseURL string) *VirtualClient
NewVirtualClient creates a client pointing at baseURL.
func (*VirtualClient) SendAnthropicV1 ¶
func (vc *VirtualClient) SendAnthropicV1(t *testing.T, s Scenario, streaming bool) *ParsedResponse
SendAnthropicV1 sends a request to the Anthropic Messages endpoint.
func (*VirtualClient) SendAnthropicV1Model ¶
func (vc *VirtualClient) SendAnthropicV1Model(t *testing.T, modelID string, streaming bool) *ParsedResponse
SendAnthropicV1Model sends a request to the Anthropic Messages endpoint using the specified model ID instead of the scenario-derived default.
func (*VirtualClient) SendGoogle ¶
func (vc *VirtualClient) SendGoogle(t *testing.T, s Scenario, streaming bool) *ParsedResponse
SendGoogle sends a request to the Google GenerateContent endpoint.
func (*VirtualClient) SendOpenAIChat ¶
func (vc *VirtualClient) SendOpenAIChat(t *testing.T, s Scenario, streaming bool) *ParsedResponse
SendOpenAIChat sends a request to the OpenAI Chat Completions endpoint.
func (*VirtualClient) SendOpenAIChatModel ¶
func (vc *VirtualClient) SendOpenAIChatModel(t *testing.T, modelID string, streaming bool) *ParsedResponse
SendOpenAIChatModel sends a request to the OpenAI Chat Completions endpoint using the specified model ID instead of the scenario-derived default.
func (*VirtualClient) SendOpenAIResponses ¶
func (vc *VirtualClient) SendOpenAIResponses(t *testing.T, s Scenario, streaming bool) *ParsedResponse
SendOpenAIResponses sends a request to the OpenAI Responses API endpoint.
func (*VirtualClient) WithServer ¶
func (vc *VirtualClient) WithServer(vs *VirtualServer) *VirtualClient
WithServer binds the client to a VirtualServer. When bound, Send* methods auto-register the scenario before firing the request.
type VirtualServer ¶
type VirtualServer struct {
// contains filtered or unexported fields
}
VirtualServer is a mock provider server backed by httptest.Server. It speaks OpenAI, Anthropic, and Google response formats and returns pre-configured scenario responses.
func NewVirtualServer ¶
func NewVirtualServer(t *testing.T) *VirtualServer
NewVirtualServer creates a new VirtualServer and registers cleanup with t.
func NewVirtualServerForCLI ¶
func NewVirtualServerForCLI() *VirtualServer
NewVirtualServerForCLI creates a new VirtualServer for CLI use (without testing.T). The caller must call Close() to clean up resources.
func (*VirtualServer) CallCount ¶
func (vs *VirtualServer) CallCount() int
CallCount returns the total number of requests received.
func (*VirtualServer) Client ¶
func (vs *VirtualServer) Client() *VirtualClient
Client returns a VirtualClient pre-pointed at this VirtualServer and bound to it.
func (*VirtualServer) RegisterScenario ¶
func (vs *VirtualServer) RegisterScenario(s Scenario)
RegisterScenario registers a scenario so the virtual server can serve its mock responses.
func (*VirtualServer) URL ¶
func (vs *VirtualServer) URL() string
URL returns the base URL of the virtual server.