Documentation
¶
Overview ¶
Package testutil provides shared test utilities for llm-router tests.
Index ¶
- func BuildCredential(providerID string, options ...func(*models.Credential)) *models.Credential
- func BuildProvider(typeKey string, options ...func(*models.ProviderInstance)) *models.ProviderInstance
- func BuildRequest(model models.ModelId, options ...func(*models.ChatCompletionRequest)) *models.ChatCompletionRequest
- func BuildToken(options ...func(*models.RouterToken)) *models.RouterToken
- func InstallTestCredentialKey(t testing.TB)
- func MakeAuthRequest(method, url, token string, body io.Reader) *http.Request
- func ParseSSEStream(reader io.Reader) ([]models.StreamChunk, error)
- func SetupTestSQLite(t *testing.T) *db.Database
- func WithCredentialData(data map[string]any) func(*models.Credential)
- func WithCredentialExpiry(t time.Time) func(*models.Credential)
- func WithCredentialLastUsed(t time.Time) func(*models.Credential)
- func WithMessages(messages []models.ChatMessage) func(*models.ChatCompletionRequest)
- func WithProviderName(name string) func(*models.ProviderInstance)
- func WithProviderQualifier(qualifier string) func(*models.ProviderInstance)
- func WithStreaming(stream bool) func(*models.ChatCompletionRequest)
- func WithTokenHash(hash string) func(*models.RouterToken)
- func WithTokenName(name string) func(*models.RouterToken)
- func WithTokenRules(rules models.TokenRules) func(*models.RouterToken)
- type MockAdapter
- func (m *MockAdapter) Complete(ctx context.Context, credentials []*models.Credential, ...) (*models.ChatCompletionResponse, error)
- func (m *MockAdapter) CompleteStream(ctx context.Context, credentials []*models.Credential, ...) error
- func (m *MockAdapter) GetModelInfos(ctx context.Context, credential *models.Credential, _ map[string]any) ([]models.ModelInfo, error)
- func (m *MockAdapter) NeedsRefresh(credential *models.Credential) bool
- func (m *MockAdapter) RefreshCredential(ctx context.Context, credential *models.Credential) (map[string]any, error)
- func (m *MockAdapter) TypeKey() string
- func (m *MockAdapter) ValidateCredentials(data map[string]any) error
- func (m *MockAdapter) WithCompleteFunc(...) *MockAdapter
- func (m *MockAdapter) WithCompleteStreamFunc(...) *MockAdapter
- func (m *MockAdapter) WithModelInfos(modelInfos []models.ModelInfo) *MockAdapter
- func (m *MockAdapter) WithNeedsRefreshFunc(f func(*models.Credential) bool) *MockAdapter
- func (m *MockAdapter) WithRefreshFunc(f func(context.Context, *models.Credential) (map[string]any, error)) *MockAdapter
- func (m *MockAdapter) WithValidateFunc(f func(map[string]any) error) *MockAdapter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildCredential ¶
func BuildCredential(providerID string, options ...func(*models.Credential)) *models.Credential
BuildCredential creates a test credential with defaults.
func BuildProvider ¶
func BuildProvider(typeKey string, options ...func(*models.ProviderInstance)) *models.ProviderInstance
BuildProvider creates a test provider instance.
func BuildRequest ¶
func BuildRequest(model models.ModelId, options ...func(*models.ChatCompletionRequest)) *models.ChatCompletionRequest
BuildRequest creates a test chat completion request.
func BuildToken ¶
func BuildToken(options ...func(*models.RouterToken)) *models.RouterToken
BuildToken creates a test token with defaults.
func InstallTestCredentialKey ¶ added in v0.6.9
InstallTestCredentialKey installs the fixed test key for credential data encryption. SetupTestSQLite calls it; tests opening databases another way call it directly.
func MakeAuthRequest ¶
MakeAuthRequest creates an HTTP request with bearer token.
func ParseSSEStream ¶
func ParseSSEStream(reader io.Reader) ([]models.StreamChunk, error)
ParseSSEStream parses Server-Sent Events from response body.
func SetupTestSQLite ¶ added in v0.4.0
SetupTestSQLite creates temporary SQLite database and cache files for testing with the full migrated schema. Cleanup closes the pools and removes the files.
func WithCredentialData ¶
func WithCredentialData(data map[string]any) func(*models.Credential)
WithCredentialData sets credential data.
func WithCredentialExpiry ¶
func WithCredentialExpiry(t time.Time) func(*models.Credential)
WithCredentialExpiry sets credential expiry time.
func WithCredentialLastUsed ¶
func WithCredentialLastUsed(t time.Time) func(*models.Credential)
WithCredentialLastUsed sets last used time.
func WithMessages ¶
func WithMessages(messages []models.ChatMessage) func(*models.ChatCompletionRequest)
WithMessages sets request messages.
func WithProviderName ¶
func WithProviderName(name string) func(*models.ProviderInstance)
WithProviderName sets provider name.
func WithProviderQualifier ¶
func WithProviderQualifier(qualifier string) func(*models.ProviderInstance)
WithProviderQualifier sets provider qualifier.
func WithStreaming ¶
func WithStreaming(stream bool) func(*models.ChatCompletionRequest)
WithStreaming sets streaming flag.
func WithTokenHash ¶
func WithTokenHash(hash string) func(*models.RouterToken)
WithTokenHash sets token hash.
func WithTokenName ¶
func WithTokenName(name string) func(*models.RouterToken)
WithTokenName sets token name.
func WithTokenRules ¶
func WithTokenRules(rules models.TokenRules) func(*models.RouterToken)
WithTokenRules sets token rules.
Types ¶
type MockAdapter ¶
type MockAdapter struct {
// Calls counts Complete invocations; SeenPools records each call's pool.
Calls int
SeenPools [][]*models.Credential
// contains filtered or unexported fields
}
MockAdapter is a simple, configurable test adapter using models types.
func NewMockAdapter ¶
func NewMockAdapter(typeKey string) *MockAdapter
NewMockAdapter creates a mock adapter with sensible defaults.
func (*MockAdapter) Complete ¶
func (m *MockAdapter) Complete(ctx context.Context, credentials []*models.Credential, request *models.ChatCompletionRequest, _ map[string]any) (*models.ChatCompletionResponse, error)
func (*MockAdapter) CompleteStream ¶
func (m *MockAdapter) CompleteStream(ctx context.Context, credentials []*models.Credential, request *models.ChatCompletionRequest, writer io.Writer, _ map[string]any) error
func (*MockAdapter) GetModelInfos ¶
func (m *MockAdapter) GetModelInfos(ctx context.Context, credential *models.Credential, _ map[string]any) ([]models.ModelInfo, error)
func (*MockAdapter) NeedsRefresh ¶
func (m *MockAdapter) NeedsRefresh(credential *models.Credential) bool
func (*MockAdapter) RefreshCredential ¶
func (m *MockAdapter) RefreshCredential(ctx context.Context, credential *models.Credential) (map[string]any, error)
func (*MockAdapter) TypeKey ¶
func (m *MockAdapter) TypeKey() string
func (*MockAdapter) ValidateCredentials ¶
func (m *MockAdapter) ValidateCredentials(data map[string]any) error
func (*MockAdapter) WithCompleteFunc ¶
func (m *MockAdapter) WithCompleteFunc(f func(context.Context, []*models.Credential, *models.ChatCompletionRequest) (*models.ChatCompletionResponse, error)) *MockAdapter
WithCompleteFunc configures the Complete behavior.
func (*MockAdapter) WithCompleteStreamFunc ¶
func (m *MockAdapter) WithCompleteStreamFunc(f func(context.Context, []*models.Credential, *models.ChatCompletionRequest, io.Writer) error) *MockAdapter
WithCompleteStreamFunc configures the CompleteStream behavior.
func (*MockAdapter) WithModelInfos ¶
func (m *MockAdapter) WithModelInfos(modelInfos []models.ModelInfo) *MockAdapter
WithModelInfos configures the GetModelInfos behavior.
func (*MockAdapter) WithNeedsRefreshFunc ¶ added in v0.3.7
func (m *MockAdapter) WithNeedsRefreshFunc(f func(*models.Credential) bool) *MockAdapter
WithNeedsRefreshFunc configures the NeedsRefresh behavior.
func (*MockAdapter) WithRefreshFunc ¶ added in v0.3.7
func (m *MockAdapter) WithRefreshFunc(f func(context.Context, *models.Credential) (map[string]any, error)) *MockAdapter
WithRefreshFunc configures the RefreshCredential behavior.
func (*MockAdapter) WithValidateFunc ¶
func (m *MockAdapter) WithValidateFunc(f func(map[string]any) error) *MockAdapter
WithValidateFunc configures the ValidateCredentials behavior.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mockplugin owns deterministic Lua plugin fixtures for Go tests.
|
Package mockplugin owns deterministic Lua plugin fixtures for Go tests. |