Documentation
¶
Index ¶
- func AssertJSONResponse(t *testing.T, resp *http.Response, expectedStatus int, ...)
- func CaptureRequest(handler gin.HandlerFunc) (*http.Request, map[string]interface{}, error)
- func Cleanup()
- func CreateJSONBody(data interface{}) *bytes.Buffer
- func CreateMockChatCompletionResponse(id, model, content string) map[string]interface{}
- func CreateMockChatCompletionResponseWithToolCalls(id, model, content string, toolCalls []map[string]interface{}) map[string]interface{}
- func CreateTestChatRequest(model string, messages []map[string]string) map[string]interface{}
- func CreateTestMessage(role, content string) map[string]string
- func CreateTestProvider(name, apiBase, token string) *typ.Provider
- func FindGoModRoot() (string, error)
- func RunMockProviderTests(t *testing.T)
- type MockProviderServer
- func (m *MockProviderServer) Close()
- func (m *MockProviderServer) GetCallCount(endpoint string) int
- func (m *MockProviderServer) GetLastRequest(endpoint string) map[string]interface{}
- func (m *MockProviderServer) GetURL() string
- func (m *MockProviderServer) Reset()
- func (m *MockProviderServer) SetResponse(endpoint string, response MockResponse)
- func (m *MockProviderServer) SetStreamingResponse(endpoint string, response MockStreamingResponse)
- type MockProviderTestSuite
- func (suite *MockProviderTestSuite) Cleanup()
- func (suite *MockProviderTestSuite) TestInvalidRequest()
- func (suite *MockProviderTestSuite) TestNetworkTimeout()
- func (suite *MockProviderTestSuite) TestProviderError()
- func (suite *MockProviderTestSuite) TestRequestForwarding()
- func (suite *MockProviderTestSuite) TestSuccessfulRequest()
- type MockResponse
- type MockStreamingResponse
- type TestConfigDir
- type TestServer
- func (ts *TestServer) AddTestProvider(t *testing.T, name, apiBase, apiStyle string, enabled bool)
- func (ts *TestServer) AddTestProviderWithURL(t *testing.T, name, url, apiStyle string, enabled bool)
- func (ts *TestServer) AddTestProviders(t *testing.T)
- func (ts *TestServer) AddTestRule(t *testing.T, requestModel, providerName, model string)
- func (ts *TestServer) GetProviderToken(uid string, isRealConfig bool) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertJSONResponse ¶
func AssertJSONResponse(t *testing.T, resp *http.Response, expectedStatus int, checkFields func(map[string]interface{}))
AssertJSONResponse asserts that the response is valid JSON and checks specific fields
func CaptureRequest ¶
CaptureRequest captures HTTP request details
func CreateJSONBody ¶
CreateJSONBody creates a JSON body for HTTP requests
func CreateMockChatCompletionResponse ¶
CreateMockChatCompletionResponse creates a mock chat completion response that matches OpenAI format
func CreateMockChatCompletionResponseWithToolCalls ¶
func CreateMockChatCompletionResponseWithToolCalls(id, model, content string, toolCalls []map[string]interface{}) map[string]interface{}
CreateMockChatCompletionResponseWithToolCalls creates a mock response with function/tool calls
func CreateTestChatRequest ¶
CreateTestChatRequest creates a test chat completion request
func CreateTestMessage ¶
CreateTestMessage creates a test message
func CreateTestProvider ¶
CreateTestProvider creates a test provider configuration
func FindGoModRoot ¶
func RunMockProviderTests ¶
RunMockProviderTests runs all mock provider tests
Types ¶
type MockProviderServer ¶
type MockProviderServer struct {
// contains filtered or unexported fields
}
MockProviderServer represents a mock AI provider server
func NewMockProviderServer ¶
func NewMockProviderServer() *MockProviderServer
NewMockProviderServer creates a new mock provider server
func (*MockProviderServer) Close ¶
func (m *MockProviderServer) Close()
Close closes the mock server
func (*MockProviderServer) GetCallCount ¶
func (m *MockProviderServer) GetCallCount(endpoint string) int
GetCallCount returns the number of calls to an endpoint
func (*MockProviderServer) GetLastRequest ¶
func (m *MockProviderServer) GetLastRequest(endpoint string) map[string]interface{}
GetLastRequest returns the last request body for an endpoint
func (*MockProviderServer) GetURL ¶
func (m *MockProviderServer) GetURL() string
GetURL returns the mock server URL
func (*MockProviderServer) Reset ¶
func (m *MockProviderServer) Reset()
Reset resets call counts and request history
func (*MockProviderServer) SetResponse ¶
func (m *MockProviderServer) SetResponse(endpoint string, response MockResponse)
SetResponse configures a mock response for a specific endpoint
func (*MockProviderServer) SetStreamingResponse ¶
func (m *MockProviderServer) SetStreamingResponse(endpoint string, response MockStreamingResponse)
SetStreamingResponse configures a mock streaming response for a specific endpoint
type MockProviderTestSuite ¶
type MockProviderTestSuite struct {
// contains filtered or unexported fields
}
MockProviderTestSuite provides a comprehensive test suite for provider testing
func NewMockProviderTestSuite ¶
func NewMockProviderTestSuite(t *testing.T) *MockProviderTestSuite
NewMockProviderTestSuite creates a new test suite
func (*MockProviderTestSuite) Cleanup ¶
func (suite *MockProviderTestSuite) Cleanup()
Cleanup cleans up the test suite
func (*MockProviderTestSuite) TestInvalidRequest ¶
func (suite *MockProviderTestSuite) TestInvalidRequest()
TestInvalidRequest tests handling of invalid requests
func (*MockProviderTestSuite) TestNetworkTimeout ¶
func (suite *MockProviderTestSuite) TestNetworkTimeout()
TestNetworkTimeout tests timeout handling
func (*MockProviderTestSuite) TestProviderError ¶
func (suite *MockProviderTestSuite) TestProviderError()
TestProviderError tests error handling from provider
func (*MockProviderTestSuite) TestRequestForwarding ¶
func (suite *MockProviderTestSuite) TestRequestForwarding()
TestRequestForwarding verifies correct request forwarding to provider
func (*MockProviderTestSuite) TestSuccessfulRequest ¶
func (suite *MockProviderTestSuite) TestSuccessfulRequest()
TestSuccessfulRequest tests a successful chat completion request
type MockResponse ¶
MockResponse defines a mock response configuration
type MockStreamingResponse ¶
type MockStreamingResponse struct {
Events []string
}
MockStreamingResponse defines a mock streaming response configuration
type TestConfigDir ¶
type TestConfigDir struct {
// contains filtered or unexported fields
}
TestConfigDir represents a temporary config directory for testing
func NewTestConfigDirCopy ¶
func NewTestConfigDirCopy(t *testing.T) *TestConfigDir
NewTestConfigDirCopy creates a temporary copy of the real config directory for testing purposes. It automatically cleans up the temporary directory when the test finishes.
func (*TestConfigDir) Path ¶
func (td *TestConfigDir) Path() string
Path returns the path to the temporary config directory
type TestServer ¶
type TestServer struct {
// contains filtered or unexported fields
}
TestServer represents a test server wrapper
func NewTestServer ¶
func NewTestServer(t *testing.T) *TestServer
NewTestServer creates a new test server
func NewTestServerWithAdaptor ¶
func NewTestServerWithAdaptor(t *testing.T) *TestServer
NewTestServerWithAdaptor creates a new test server with adaptor flag
func NewTestServerWithAdaptorFromConfig ¶
func NewTestServerWithAdaptorFromConfig(appConfig *config.AppConfig) *TestServer
NewTestServerWithAdaptorFromConfig creates a new test server with adaptor flag using existing app config
func NewTestServerWithConfigDir ¶
func NewTestServerWithConfigDir(t *testing.T, configDir string) *TestServer
NewTestServer creates a new test server with custom config directory
func (*TestServer) AddTestProvider ¶
func (ts *TestServer) AddTestProvider(t *testing.T, name, apiBase, apiStyle string, enabled bool)
AddTestProvider adds a single test provider
func (*TestServer) AddTestProviderWithURL ¶
func (ts *TestServer) AddTestProviderWithURL(t *testing.T, name, url, apiStyle string, enabled bool)
AddTestProviderWithURL adds a provider with a specific URL
func (*TestServer) AddTestProviders ¶
func (ts *TestServer) AddTestProviders(t *testing.T)
AddTestProviders adds test providers to the configuration
func (*TestServer) AddTestRule ¶
func (ts *TestServer) AddTestRule(t *testing.T, requestModel, providerName, model string)
AddTestRule adds a test rule that routes to a specific provider
func (*TestServer) GetProviderToken ¶
func (ts *TestServer) GetProviderToken(uid string, isRealConfig bool) string
GetProviderToken returns the appropriate token for Anthropic API requests