testutil

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package testutil provides shared test utilities for llm-router tests.

Index

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 MakeAuthRequest

func MakeAuthRequest(method, url, token string, body io.Reader) *http.Request

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

func SetupTestSQLite(t *testing.T) *db.Database

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

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.

Jump to

Keyboard shortcuts

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