Documentation
¶
Overview ¶
Package testing provides common testing helpers and utilities for AI provider implementations including authentication, configuration, tool calling, and mock server functionality.
Index ¶
- func AssertContains(t *testing.T, s, substr string)
- func CleanCodeResponse(response string) string
- func CreateMockChatCompletionResponse(model, content string, toolCalls []types.ToolCall) map[string]interface{}
- func CreateMockStreamResponse(model, content string, toolCalls []types.ToolCall) []string
- func CreateTestTool(name, description string) types.Tool
- func CreateTestToolCall(id, name, arguments string) types.ToolCall
- func RunProviderTests(t *testing.T, provider types.Provider, config types.ProviderConfig, ...)
- func TestProviderInterface(t *testing.T, provider types.Provider)
- type AuthTestHelper
- func (a *AuthTestHelper) CreateAPIKeyAuthConfig(apiKey, baseURL, defaultModel string) types.AuthConfig
- func (a *AuthTestHelper) CreateBearerTokenAuthConfig(token string) types.AuthConfig
- func (a *AuthTestHelper) CreateOAuthAuthConfig(clientID, clientSecret string) types.AuthConfig
- func (a *AuthTestHelper) StandardAuthTestSuite(provider types.Provider)
- func (a *AuthTestHelper) TestAPIKeyAuthentication(provider types.Provider)
- func (a *AuthTestHelper) TestAuthenticationErrors(provider types.Provider)
- func (a *AuthTestHelper) TestAuthenticationPersistence(provider types.Provider)
- func (a *AuthTestHelper) TestAuthenticationWithConfig(provider types.Provider)
- func (a *AuthTestHelper) TestAuthenticationWithContext(provider types.Provider)
- func (a *AuthTestHelper) TestLogoutFunctionality(provider types.Provider)
- func (a *AuthTestHelper) TestMultiKeyAuthentication(provider types.Provider)
- func (a *AuthTestHelper) TestUnsupportedAuthMethods(provider types.Provider)
- type ConfigTestHelper
- func (c *ConfigTestHelper) AssertConfigEquals(expected, actual types.ProviderConfig)
- func (c *ConfigTestHelper) AssertConfigValid(config types.ProviderConfig, providerType types.ProviderType)
- func (c *ConfigTestHelper) CreateMinimalConfig(providerType types.ProviderType) types.ProviderConfig
- func (c *ConfigTestHelper) CreateMultiKeyConfig(providerType types.ProviderType) types.ProviderConfig
- func (c *ConfigTestHelper) CreateOAuthConfig(providerType types.ProviderType) types.ProviderConfig
- func (c *ConfigTestHelper) CreateTestConfig(providerType types.ProviderType) types.ProviderConfig
- func (c *ConfigTestHelper) StandardConfigTestSuite(provider types.Provider)
- func (c *ConfigTestHelper) TestConfigurationPersistence(provider types.Provider)
- func (c *ConfigTestHelper) TestConfigurationUpdates(provider types.Provider)
- func (c *ConfigTestHelper) TestDisplayName(provider types.Provider)
- func (c *ConfigTestHelper) TestInvalidConfiguration(provider types.Provider)
- func (c *ConfigTestHelper) TestMultipleAPIKeys(provider types.Provider)
- type MockServer
- type MockStream
- type ProviderTestHelpers
- func (p *ProviderTestHelpers) AssertAuthenticated(expected bool)
- func (p *ProviderTestHelpers) AssertDefaultModel(expectedModel string)
- func (p *ProviderTestHelpers) AssertModelExists(expectedModelID string)
- func (p *ProviderTestHelpers) AssertProviderBasics(expectedName, expectedType string)
- func (p *ProviderTestHelpers) AssertSupportsFeatures(toolCalling, streaming, responsesAPI bool)
- func (p *ProviderTestHelpers) TestAuthenticationFlow(authConfig types.AuthConfig)
- func (p *ProviderTestHelpers) TestConfiguration(config types.ProviderConfig)
- func (p *ProviderTestHelpers) TestHealthCheck()
- func (p *ProviderTestHelpers) TestMetrics()
- type ToolCallTestHelper
- func (th *ToolCallTestHelper) AssertToolCallInStreamingChunk(chunk types.ChatCompletionChunk)
- func (th *ToolCallTestHelper) AssertToolCallsInChunk(chunk types.ChatCompletionChunk, expectedToolCalls []types.ToolCall)
- func (th *ToolCallTestHelper) CreateMockStreamingToolCallServer(toolCalls []types.ToolCall) *httptest.Server
- func (th *ToolCallTestHelper) CreateMockToolCallServer(toolCalls []types.ToolCall) *httptest.Server
- func (th *ToolCallTestHelper) CreateParallelToolCalls() []types.ToolCall
- func (th *ToolCallTestHelper) StandardToolTestSuite(provider types.Provider)
- func (th *ToolCallTestHelper) TestParallelToolCalls(provider types.Provider)
- func (th *ToolCallTestHelper) TestToolCallConversion(provider types.Provider, tools []types.Tool, expectedInRequest bool)
- func (th *ToolCallTestHelper) TestToolChoiceModes(provider types.Provider, tools []types.Tool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertContains ¶
AssertContains checks if a string contains a substring (helper function)
func CleanCodeResponse ¶
CleanCodeResponse removes markdown code blocks and language identifiers
func CreateMockChatCompletionResponse ¶
func CreateMockChatCompletionResponse(model, content string, toolCalls []types.ToolCall) map[string]interface{}
CreateMockChatCompletionResponse creates a mock chat completion response
func CreateMockStreamResponse ¶
CreateMockStreamResponse creates a mock streaming response
func CreateTestTool ¶
CreateTestTool creates a standard test tool for testing tool calling
func CreateTestToolCall ¶
CreateTestToolCall creates a standard test tool call for testing
func RunProviderTests ¶
func RunProviderTests(t *testing.T, provider types.Provider, config types.ProviderConfig, expectedModels []string)
RunProviderTests runs a comprehensive set of tests on a provider
Types ¶
type AuthTestHelper ¶
type AuthTestHelper struct {
// contains filtered or unexported fields
}
AuthTestHelper provides helpers for testing authentication functionality
func NewAuthTestHelper ¶
func NewAuthTestHelper(t *testing.T) *AuthTestHelper
NewAuthTestHelper creates a new authentication test helper
func (*AuthTestHelper) CreateAPIKeyAuthConfig ¶
func (a *AuthTestHelper) CreateAPIKeyAuthConfig(apiKey, baseURL, defaultModel string) types.AuthConfig
CreateAPIKeyAuthConfig creates an API key authentication configuration
func (*AuthTestHelper) CreateBearerTokenAuthConfig ¶
func (a *AuthTestHelper) CreateBearerTokenAuthConfig(token string) types.AuthConfig
CreateBearerTokenAuthConfig creates a bearer token authentication configuration
func (*AuthTestHelper) CreateOAuthAuthConfig ¶
func (a *AuthTestHelper) CreateOAuthAuthConfig(clientID, clientSecret string) types.AuthConfig
CreateOAuthAuthConfig creates an OAuth authentication configuration
func (*AuthTestHelper) StandardAuthTestSuite ¶
func (a *AuthTestHelper) StandardAuthTestSuite(provider types.Provider)
StandardAuthTestSuite runs a comprehensive set of authentication tests
func (*AuthTestHelper) TestAPIKeyAuthentication ¶
func (a *AuthTestHelper) TestAPIKeyAuthentication(provider types.Provider)
TestAPIKeyAuthentication tests API key authentication flow
func (*AuthTestHelper) TestAuthenticationErrors ¶
func (a *AuthTestHelper) TestAuthenticationErrors(provider types.Provider)
TestAuthenticationErrors tests various authentication error scenarios
func (*AuthTestHelper) TestAuthenticationPersistence ¶
func (a *AuthTestHelper) TestAuthenticationPersistence(provider types.Provider)
TestAuthenticationPersistence tests that authentication state persists
func (*AuthTestHelper) TestAuthenticationWithConfig ¶
func (a *AuthTestHelper) TestAuthenticationWithConfig(provider types.Provider)
TestAuthenticationWithConfig tests authentication through configuration
func (*AuthTestHelper) TestAuthenticationWithContext ¶
func (a *AuthTestHelper) TestAuthenticationWithContext(provider types.Provider)
TestAuthenticationWithContext tests authentication with context
func (*AuthTestHelper) TestLogoutFunctionality ¶
func (a *AuthTestHelper) TestLogoutFunctionality(provider types.Provider)
TestLogoutFunctionality tests logout functionality
func (*AuthTestHelper) TestMultiKeyAuthentication ¶
func (a *AuthTestHelper) TestMultiKeyAuthentication(provider types.Provider)
TestMultiKeyAuthentication tests authentication with multiple API keys
func (*AuthTestHelper) TestUnsupportedAuthMethods ¶
func (a *AuthTestHelper) TestUnsupportedAuthMethods(provider types.Provider)
TestUnsupportedAuthMethods tests that unsupported auth methods are rejected
type ConfigTestHelper ¶
type ConfigTestHelper struct {
// contains filtered or unexported fields
}
ConfigTestHelper provides helpers for testing provider configurations
func NewConfigTestHelper ¶
func NewConfigTestHelper(t *testing.T) *ConfigTestHelper
NewConfigTestHelper creates a new configuration test helper
func (*ConfigTestHelper) AssertConfigEquals ¶
func (c *ConfigTestHelper) AssertConfigEquals(expected, actual types.ProviderConfig)
AssertConfigEquals tests that two configurations are equal
func (*ConfigTestHelper) AssertConfigValid ¶
func (c *ConfigTestHelper) AssertConfigValid(config types.ProviderConfig, providerType types.ProviderType)
AssertConfigValid tests that a configuration is valid for the given provider type
func (*ConfigTestHelper) CreateMinimalConfig ¶
func (c *ConfigTestHelper) CreateMinimalConfig(providerType types.ProviderType) types.ProviderConfig
CreateMinimalConfig creates a minimal configuration with just the required fields
func (*ConfigTestHelper) CreateMultiKeyConfig ¶
func (c *ConfigTestHelper) CreateMultiKeyConfig(providerType types.ProviderType) types.ProviderConfig
CreateMultiKeyConfig creates a configuration with multiple API keys
func (*ConfigTestHelper) CreateOAuthConfig ¶
func (c *ConfigTestHelper) CreateOAuthConfig(providerType types.ProviderType) types.ProviderConfig
CreateOAuthConfig creates a configuration for OAuth authentication
func (*ConfigTestHelper) CreateTestConfig ¶
func (c *ConfigTestHelper) CreateTestConfig(providerType types.ProviderType) types.ProviderConfig
CreateTestConfig creates a standard test configuration for a provider
func (*ConfigTestHelper) StandardConfigTestSuite ¶
func (c *ConfigTestHelper) StandardConfigTestSuite(provider types.Provider)
StandardConfigTestSuite runs a comprehensive set of configuration tests
func (*ConfigTestHelper) TestConfigurationPersistence ¶
func (c *ConfigTestHelper) TestConfigurationPersistence(provider types.Provider)
TestConfigurationPersistence tests that configuration persists across operations
func (*ConfigTestHelper) TestConfigurationUpdates ¶
func (c *ConfigTestHelper) TestConfigurationUpdates(provider types.Provider)
TestConfigurationUpdates tests that configuration updates work correctly
func (*ConfigTestHelper) TestDisplayName ¶
func (c *ConfigTestHelper) TestDisplayName(provider types.Provider)
TestDisplayName tests that display names work correctly
func (*ConfigTestHelper) TestInvalidConfiguration ¶
func (c *ConfigTestHelper) TestInvalidConfiguration(provider types.Provider)
TestInvalidConfiguration tests that invalid configurations are rejected
func (*ConfigTestHelper) TestMultipleAPIKeys ¶
func (c *ConfigTestHelper) TestMultipleAPIKeys(provider types.Provider)
TestMultipleAPIKeys tests that multiple API keys are handled correctly
type MockServer ¶
type MockServer struct {
// contains filtered or unexported fields
}
MockServer represents a configurable mock HTTP server for testing providers
func CreateStreamingMockServer ¶
func CreateStreamingMockServer(chunks []string) *MockServer
CreateStreamingMockServer creates a mock server that streams responses
func NewMockServer ¶
func NewMockServer(response string, statusCode int) *MockServer
NewMockServer creates a new mock server with the given response and status code
func (*MockServer) SetHeader ¶
func (m *MockServer) SetHeader(key, value string)
SetHeader sets a header that will be returned by the mock server
func (*MockServer) Start ¶
func (m *MockServer) Start() string
Start starts the mock server and returns the URL
type MockStream ¶
type MockStream struct {
// contains filtered or unexported fields
}
MockStream provides a mock implementation of ChatCompletionStream for testing
func NewMockStream ¶
func NewMockStream(chunks []types.ChatCompletionChunk) *MockStream
NewMockStream creates a new mock stream with the given chunks
func (*MockStream) Close ¶
func (m *MockStream) Close() error
Close resets the stream to the beginning
func (*MockStream) Next ¶
func (m *MockStream) Next() (types.ChatCompletionChunk, error)
Next returns the next chunk from the stream
type ProviderTestHelpers ¶
type ProviderTestHelpers struct {
// contains filtered or unexported fields
}
ProviderTestHelpers provides common helper functions for provider testing
func NewProviderTestHelpers ¶
func NewProviderTestHelpers(t *testing.T, provider types.Provider) *ProviderTestHelpers
NewProviderTestHelpers creates a new helper instance for testing providers
func (*ProviderTestHelpers) AssertAuthenticated ¶
func (p *ProviderTestHelpers) AssertAuthenticated(expected bool)
AssertAuthenticated tests authentication state
func (*ProviderTestHelpers) AssertDefaultModel ¶
func (p *ProviderTestHelpers) AssertDefaultModel(expectedModel string)
AssertDefaultModel tests the default model functionality
func (*ProviderTestHelpers) AssertModelExists ¶
func (p *ProviderTestHelpers) AssertModelExists(expectedModelID string)
AssertModelExists checks that a model with the given ID exists in the model list
func (*ProviderTestHelpers) AssertProviderBasics ¶
func (p *ProviderTestHelpers) AssertProviderBasics(expectedName, expectedType string)
AssertProviderBasics tests basic provider functionality
func (*ProviderTestHelpers) AssertSupportsFeatures ¶
func (p *ProviderTestHelpers) AssertSupportsFeatures(toolCalling, streaming, responsesAPI bool)
AssertSupportsFeatures tests provider feature support
func (*ProviderTestHelpers) TestAuthenticationFlow ¶
func (p *ProviderTestHelpers) TestAuthenticationFlow(authConfig types.AuthConfig)
TestAuthenticationFlow tests a complete authentication flow
func (*ProviderTestHelpers) TestConfiguration ¶
func (p *ProviderTestHelpers) TestConfiguration(config types.ProviderConfig)
TestConfiguration tests provider configuration
func (*ProviderTestHelpers) TestHealthCheck ¶
func (p *ProviderTestHelpers) TestHealthCheck()
TestHealthCheck tests the provider health check
func (*ProviderTestHelpers) TestMetrics ¶
func (p *ProviderTestHelpers) TestMetrics()
TestMetrics tests the provider metrics
type ToolCallTestHelper ¶
type ToolCallTestHelper struct {
// contains filtered or unexported fields
}
ToolCallTestHelper provides helpers for testing tool calling functionality
func NewToolCallTestHelper ¶
func NewToolCallTestHelper(t *testing.T) *ToolCallTestHelper
NewToolCallTestHelper creates a new tool call test helper
func (*ToolCallTestHelper) AssertToolCallInStreamingChunk ¶
func (th *ToolCallTestHelper) AssertToolCallInStreamingChunk(chunk types.ChatCompletionChunk)
AssertToolCallInStreamingChunk verifies tool calls in streaming response
func (*ToolCallTestHelper) AssertToolCallsInChunk ¶
func (th *ToolCallTestHelper) AssertToolCallsInChunk(chunk types.ChatCompletionChunk, expectedToolCalls []types.ToolCall)
AssertToolCallsInChunk verifies that tool calls are present in a response chunk
func (*ToolCallTestHelper) CreateMockStreamingToolCallServer ¶
func (th *ToolCallTestHelper) CreateMockStreamingToolCallServer(toolCalls []types.ToolCall) *httptest.Server
CreateMockStreamingToolCallServer creates a mock server that streams tool calls
func (*ToolCallTestHelper) CreateMockToolCallServer ¶
func (th *ToolCallTestHelper) CreateMockToolCallServer(toolCalls []types.ToolCall) *httptest.Server
CreateMockToolCallServer creates a mock server that returns tool calls in responses
func (*ToolCallTestHelper) CreateParallelToolCalls ¶
func (th *ToolCallTestHelper) CreateParallelToolCalls() []types.ToolCall
CreateParallelToolCalls creates multiple tool calls for testing parallel execution
func (*ToolCallTestHelper) StandardToolTestSuite ¶
func (th *ToolCallTestHelper) StandardToolTestSuite(provider types.Provider)
StandardToolTestSuite runs a comprehensive set of tool calling tests
func (*ToolCallTestHelper) TestParallelToolCalls ¶
func (th *ToolCallTestHelper) TestParallelToolCalls(provider types.Provider)
TestParallelToolCalls tests that a provider can handle multiple tool calls in one response
func (*ToolCallTestHelper) TestToolCallConversion ¶
func (th *ToolCallTestHelper) TestToolCallConversion( provider types.Provider, tools []types.Tool, expectedInRequest bool, )
TestToolCallConversion tests that tool calls are properly converted between formats
func (*ToolCallTestHelper) TestToolChoiceModes ¶
func (th *ToolCallTestHelper) TestToolChoiceModes( provider types.Provider, tools []types.Tool, )
TestToolChoiceModes tests different tool choice modes (auto, required, none, specific)