util

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AliyunTestConfig

func AliyunTestConfig(apiKey string) *config.Config

AliyunTestConfig returns a configuration for Aliyun (Qwen) testing.

func AnthropicTestConfig

func AnthropicTestConfig(apiKey string) *config.Config

AnthropicTestConfig returns a configuration for Anthropic testing.

func AssertContains

func AssertContains(t *testing.T, s, substr string, msg string)

AssertContains asserts that a string contains a substring.

func AssertEqual

func AssertEqual(t *testing.T, expected, actual interface{}, msg string)

AssertEqual asserts that two values are equal.

func AssertError

func AssertError(t *testing.T, err error, msg string)

AssertError asserts that an error is not nil.

func AssertHasHeader

func AssertHasHeader(t *testing.T, resp *http.Response, key, msg string)

AssertHasHeader asserts that an HTTP response contains a header (any value).

func AssertHeader

func AssertHeader(t *testing.T, resp *http.Response, key, expected string, msg string)

AssertHeader asserts that an HTTP response contains a specific header.

func AssertJSONEqual

func AssertJSONEqual(t *testing.T, expected, actual string, msg string)

AssertJSONEqual asserts that two JSON strings are semantically equal.

func AssertLen

func AssertLen(t *testing.T, obj interface{}, expected int, msg string)

AssertLen asserts that a slice/map has the expected length.

func AssertNil

func AssertNil(t *testing.T, v interface{}, msg string)

AssertNil asserts that a value is nil.

func AssertNoError

func AssertNoError(t *testing.T, err error, msg string)

AssertNoError asserts that an error is nil.

func AssertNonEmpty

func AssertNonEmpty(t *testing.T, s, msg string)

AssertNonEmpty asserts that a string is not empty.

func AssertNotContains

func AssertNotContains(t *testing.T, s, substr string, msg string)

AssertNotContains asserts that a string does not contain a substring.

func AssertNotEqual

func AssertNotEqual(t *testing.T, expected, actual interface{}, msg string)

AssertNotEqual asserts that two values are not equal.

func AssertNotNil

func AssertNotNil(t *testing.T, v interface{}, msg string)

AssertNotNil asserts that a value is not nil.

func AssertPositive

func AssertPositive(t *testing.T, n int, msg string)

AssertPositive asserts that a number is positive (> 0).

func AssertSSEStreaming

func AssertSSEStreaming(t *testing.T, data string, requiredEvents []string, msg string)

AssertSSEStreaming asserts that SSE data contains required events.

func AssertStatusCode

func AssertStatusCode(t *testing.T, resp *http.Response, expected int, msg string)

AssertStatusCode asserts that an HTTP response has the expected status code.

func AssertStreamEvent

func AssertStreamEvent(t *testing.T, event, eventType, dataPrefix string, msg string)

AssertStreamEvent asserts that an SSE event has the expected structure.

func BigModelTestConfig

func BigModelTestConfig(apiKey string) *config.Config

BigModelTestConfig returns a configuration for BigModel (GLM) testing.

func FailoverTestConfig

func FailoverTestConfig() *config.Config

FailoverTestConfig returns a configuration for failover testing.

func GeminiTestConfig

func GeminiTestConfig(apiKey string) *config.Config

GeminiTestConfig returns a configuration for Gemini testing.

func GetAPIKey

func GetAPIKey(provider string) string

GetAPIKey retrieves an API key from environment variables.

func HasAPIKey

func HasAPIKey(provider string) bool

HasAPIKey checks if an API key is available for a provider.

func LogWithTimestamp

func LogWithTimestamp(t *testing.T, format string, args ...interface{})

LogWithTimestamp logs a message with timestamp for debugging.

func MaskAPIKey

func MaskAPIKey(key string) string

MaskAPIKey masks an API key for logging (shows first 8 and last 4 chars).

func MiniMaxTestConfig

func MiniMaxTestConfig(apiKey string) *config.Config

MiniMaxTestConfig returns a configuration for MiniMax testing.

func MinimalTestConfig

func MinimalTestConfig() *config.Config

MinimalTestConfig returns a minimal test configuration for testing.

func OpenAITestConfig

func OpenAITestConfig(apiKey string) *config.Config

OpenAITestConfig returns a configuration for OpenAI testing.

func OpenRouterTestConfig

func OpenRouterTestConfig(apiKey string) *config.Config

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

func SkipIfEnvNotSet(t *testing.T, envVar string)

SkipIfEnvNotSet skips the test if the given environment variable is not set.

func SkipWithReason

func SkipWithReason(t *testing.T, reason string)

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 NewMockServer

func NewMockServer() *MockServer

NewMockServer creates a new mock HTTP server.

func (*MockServer) ClearResponses

func (ms *MockServer) ClearResponses()

ClearResponses clears all configured responses.

func (*MockServer) Close

func (ms *MockServer) Close()

Close closes the mock server.

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.

func (*MockServer) URL

func (ms *MockServer) URL() string

URL returns the mock server's URL.

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

func GetProviderInfo(name string) *Provider

GetProviderInfo returns provider information by name.

type SkipFunc

type SkipFunc func() (skip bool, reason string)

SkipFunc is a function that determines whether to skip a test.

func SkipIfNoKey

func SkipIfNoKey(provider string) SkipFunc

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL