Documentation
¶
Overview ¶
Package util provides testing utilities for integration tests.
Package util provides testing utilities for integration tests.
Package util provides testing utilities for integration tests.
Package util provides testing utilities for integration tests.
Index ¶
- func AliyunTestConfig(apiKey string) *config.Config
- func AnthropicTestConfig(apiKey string) *config.Config
- func AssertContains(t *testing.T, s, substr string, msg string)
- func AssertEqual(t *testing.T, expected, actual interface{}, msg string)
- func AssertError(t *testing.T, err error, msg string)
- func AssertHasHeader(t *testing.T, resp *http.Response, key, msg string)
- func AssertHeader(t *testing.T, resp *http.Response, key, expected string, msg string)
- func AssertJSONEqual(t *testing.T, expected, actual string, msg string)
- func AssertLen(t *testing.T, obj interface{}, expected int, msg string)
- func AssertNil(t *testing.T, v interface{}, msg string)
- func AssertNoError(t *testing.T, err error, msg string)
- func AssertNonEmpty(t *testing.T, s, msg string)
- func AssertNotContains(t *testing.T, s, substr string, msg string)
- func AssertNotEqual(t *testing.T, expected, actual interface{}, msg string)
- func AssertNotNil(t *testing.T, v interface{}, msg string)
- func AssertPositive(t *testing.T, n int, msg string)
- func AssertSSEStreaming(t *testing.T, data string, requiredEvents []string, msg string)
- func AssertStatusCode(t *testing.T, resp *http.Response, expected int, msg string)
- func AssertStreamEvent(t *testing.T, event, eventType, dataPrefix string, msg string)
- func BigModelTestConfig(apiKey string) *config.Config
- func FailoverTestConfig() *config.Config
- func GeminiTestConfig(apiKey string) *config.Config
- func GetAPIKey(provider string) string
- func HasAPIKey(provider string) bool
- func LogWithTimestamp(t *testing.T, format string, args ...interface{})
- func MaskAPIKey(key string) string
- func MiniMaxTestConfig(apiKey string) *config.Config
- func MinimalTestConfig() *config.Config
- func OpenAITestConfig(apiKey string) *config.Config
- func OpenRouterTestConfig(apiKey string) *config.Config
- func SkipIfEnvNotSet(t *testing.T, envVar string)
- func SkipWithReason(t *testing.T, reason string)
- type MockResponse
- type MockServer
- func (ms *MockServer) ClearResponses()
- func (ms *MockServer) Close()
- func (ms *MockServer) GetRequestCount() int
- func (ms *MockServer) GetRequests() []*http.Request
- func (ms *MockServer) Reset()
- func (ms *MockServer) SetDelay(delay time.Duration)
- func (ms *MockServer) SetErrorOn(n int, status int)
- func (ms *MockServer) SetResponse(path string, statusCode int, body string, headers map[string]string)
- func (ms *MockServer) URL() string
- type Provider
- type SkipFunc
- type TestConfigBuilder
- func (b *TestConfigBuilder) Build() *config.Config
- func (b *TestConfigBuilder) WithLogging(enabled bool, destination, level string) *TestConfigBuilder
- func (b *TestConfigBuilder) WithProvider(name, baseURL, apiKey string, models []string, transformer string) *TestConfigBuilder
- func (b *TestConfigBuilder) WithRetryConfig(maxRetries int, retryDelay string) *TestConfigBuilder
- func (b *TestConfigBuilder) WithRoute(model, target string) *TestConfigBuilder
- func (b *TestConfigBuilder) WithServer(host string, port int) *TestConfigBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AliyunTestConfig ¶
AliyunTestConfig returns a configuration for Aliyun (Qwen) testing.
func AnthropicTestConfig ¶
AnthropicTestConfig returns a configuration for Anthropic testing.
func AssertContains ¶
AssertContains asserts that a string contains a substring.
func AssertEqual ¶
AssertEqual asserts that two values are equal.
func AssertError ¶
AssertError asserts that an error is not nil.
func AssertHasHeader ¶
AssertHasHeader asserts that an HTTP response contains a header (any value).
func AssertHeader ¶
AssertHeader asserts that an HTTP response contains a specific header.
func AssertJSONEqual ¶
AssertJSONEqual asserts that two JSON strings are semantically equal.
func AssertNoError ¶
AssertNoError asserts that an error is nil.
func AssertNonEmpty ¶
AssertNonEmpty asserts that a string is not empty.
func AssertNotContains ¶
AssertNotContains asserts that a string does not contain a substring.
func AssertNotEqual ¶
AssertNotEqual asserts that two values are not equal.
func AssertNotNil ¶
AssertNotNil asserts that a value is not nil.
func AssertPositive ¶
AssertPositive asserts that a number is positive (> 0).
func AssertSSEStreaming ¶
AssertSSEStreaming asserts that SSE data contains required events.
func AssertStatusCode ¶
AssertStatusCode asserts that an HTTP response has the expected status code.
func AssertStreamEvent ¶
AssertStreamEvent asserts that an SSE event has the expected structure.
func BigModelTestConfig ¶
BigModelTestConfig returns a configuration for BigModel (GLM) testing.
func FailoverTestConfig ¶
FailoverTestConfig returns a configuration for failover testing.
func GeminiTestConfig ¶
GeminiTestConfig returns a configuration for Gemini testing.
func LogWithTimestamp ¶
LogWithTimestamp logs a message with timestamp for debugging.
func MaskAPIKey ¶
MaskAPIKey masks an API key for logging (shows first 8 and last 4 chars).
func MiniMaxTestConfig ¶
MiniMaxTestConfig returns a configuration for MiniMax testing.
func MinimalTestConfig ¶
MinimalTestConfig returns a minimal test configuration for testing.
func OpenAITestConfig ¶
OpenAITestConfig returns a configuration for OpenAI testing.
func OpenRouterTestConfig ¶
OpenRouterTestConfig returns a configuration for OpenRouter testing. Note: This uses the Anthropic-compatible endpoint which only supports Anthropic models. For non-Anthropic models (Google, OpenAI, etc.), use the OpenAI-compatible endpoint with a separate provider configuration.
func SkipIfEnvNotSet ¶
SkipIfEnvNotSet skips the test if the given environment variable is not set.
func SkipWithReason ¶
SkipWithReason skips the test with the given reason.
Types ¶
type MockResponse ¶
type MockResponse struct {
StatusCode int
Body string
Headers map[string]string
Delay time.Duration
}
MockResponse represents a mock response configuration.
type MockServer ¶
type MockServer struct {
// contains filtered or unexported fields
}
MockServer is a configurable mock HTTP server for testing.
func (*MockServer) ClearResponses ¶
func (ms *MockServer) ClearResponses()
ClearResponses clears all configured responses.
func (*MockServer) GetRequestCount ¶
func (ms *MockServer) GetRequestCount() int
GetRequestCount returns the number of recorded requests.
func (*MockServer) GetRequests ¶
func (ms *MockServer) GetRequests() []*http.Request
GetRequests returns all recorded requests.
func (*MockServer) Reset ¶
func (ms *MockServer) Reset()
Reset clears all recorded requests and error state.
func (*MockServer) SetDelay ¶
func (ms *MockServer) SetDelay(delay time.Duration)
SetDelay sets a delay for all responses.
func (*MockServer) SetErrorOn ¶
func (ms *MockServer) SetErrorOn(n int, status int)
SetErrorOn sets which request number should return an error.
func (*MockServer) SetResponse ¶
func (ms *MockServer) SetResponse(path string, statusCode int, body string, headers map[string]string)
SetResponse sets a mock response for a specific path.
type Provider ¶
type Provider struct {
Name string
APIKeyEnv string
BaseURL string
Model string
Transformer string
}
Provider represents an LLM provider configuration for testing.
func AvailableProviders ¶
func AvailableProviders() []Provider
AvailableProviders returns a list of providers with available API keys.
func GetProviderInfo ¶
GetProviderInfo returns provider information by name.
type SkipFunc ¶
SkipFunc is a function that determines whether to skip a test.
func SkipIfNoKey ¶
SkipIfNoKey skips the test if the API key is not available.
type TestConfigBuilder ¶
type TestConfigBuilder struct {
// contains filtered or unexported fields
}
TestConfigBuilder helps build test configurations.
func NewTestConfigBuilder ¶
func NewTestConfigBuilder() *TestConfigBuilder
NewTestConfigBuilder creates a new test configuration builder.
func (*TestConfigBuilder) Build ¶
func (b *TestConfigBuilder) Build() *config.Config
Build returns the built configuration.
func (*TestConfigBuilder) WithLogging ¶
func (b *TestConfigBuilder) WithLogging(enabled bool, destination, level string) *TestConfigBuilder
WithLogging sets the logging configuration.
func (*TestConfigBuilder) WithProvider ¶
func (b *TestConfigBuilder) WithProvider(name, baseURL, apiKey string, models []string, transformer string) *TestConfigBuilder
WithProvider adds a provider configuration.
func (*TestConfigBuilder) WithRetryConfig ¶
func (b *TestConfigBuilder) WithRetryConfig(maxRetries int, retryDelay string) *TestConfigBuilder
WithRetryConfig sets the retry configuration.
func (*TestConfigBuilder) WithRoute ¶
func (b *TestConfigBuilder) WithRoute(model, target string) *TestConfigBuilder
WithRoute adds a route configuration.
func (*TestConfigBuilder) WithServer ¶
func (b *TestConfigBuilder) WithServer(host string, port int) *TestConfigBuilder
WithServer sets the server configuration.