Documentation
¶
Overview ¶
Package virtualserver 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.
Index ¶
- Constants
- type APIStyle
- type MockResponseBuilder
- type ParsedResponse
- type Scenario
- type VirtualServer
- func (vs *VirtualServer) CallCount() int
- func (vs *VirtualServer) Close()
- func (vs *VirtualServer) RegisterScenario(s Scenario)
- func (vs *VirtualServer) SendAnthropicV1(t *testing.T, s Scenario, streaming bool) *ParsedResponse
- func (vs *VirtualServer) SendGoogle(t *testing.T, s Scenario, streaming bool) *ParsedResponse
- func (vs *VirtualServer) SendOpenAIChat(t *testing.T, s Scenario, streaming bool) *ParsedResponse
- func (vs *VirtualServer) URL() string
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 the virtual server. It wraps stream.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 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 (*VirtualServer) CallCount ¶
func (vs *VirtualServer) CallCount() int
CallCount returns the total number of requests received.
func (*VirtualServer) RegisterScenario ¶
func (vs *VirtualServer) RegisterScenario(s Scenario)
RegisterScenario registers a scenario so the virtual server can serve its mock responses.
func (*VirtualServer) SendAnthropicV1 ¶
func (vs *VirtualServer) SendAnthropicV1(t *testing.T, s Scenario, streaming bool) *ParsedResponse
SendAnthropicV1 sends a request directly to the virtual server's Anthropic endpoint.
func (*VirtualServer) SendGoogle ¶
func (vs *VirtualServer) SendGoogle(t *testing.T, s Scenario, streaming bool) *ParsedResponse
SendGoogle sends a request directly to the virtual server's Google endpoint.
func (*VirtualServer) SendOpenAIChat ¶
func (vs *VirtualServer) SendOpenAIChat(t *testing.T, s Scenario, streaming bool) *ParsedResponse
SendOpenAIChat sends a request directly to the virtual server's OpenAI endpoint.
func (*VirtualServer) URL ¶
func (vs *VirtualServer) URL() string
URL returns the base URL of the virtual server.