testutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 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, opts ...func(*models.Credential)) *models.Credential

BuildCredential creates a test credential with defaults.

func BuildProvider

func BuildProvider(typeKey string, opts ...func(*models.ProviderInstance)) *models.ProviderInstance

BuildProvider creates a test provider instance.

func BuildRequest

func BuildRequest(model models.ModelId, opts ...func(*models.ChatCompletionRequest)) *models.ChatCompletionRequest

BuildRequest creates a test chat completion request.

func BuildToken

func BuildToken(opts ...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(r io.Reader) ([]models.StreamChunk, error)

ParseSSEStream parses Server-Sent Events from response body.

func SetupTestDB

func SetupTestDB(t *testing.T) *db.DB

SetupTestDB creates a temporary bbolt database for testing. The database is automatically cleaned up when the test completes.

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 WithCredentialQuota

func WithCredentialQuota(resetAt time.Time) func(*models.Credential)

WithCredentialQuota sets credential quota exceeded time.

func WithMessages

func WithMessages(msgs []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(q 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 {
	// 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 (*MockAdapter) CompleteStream

func (m *MockAdapter) CompleteStream(ctx context.Context, creds []*models.Credential, req *models.ChatCompletionRequest, w io.Writer, _ map[string]any) error

func (*MockAdapter) GetModelInfos

func (m *MockAdapter) GetModelInfos(ctx context.Context, cred *models.Credential, _ map[string]any) ([]models.ModelInfo, error)

func (*MockAdapter) NeedsRefresh

func (m *MockAdapter) NeedsRefresh(cred *models.Credential) bool

func (*MockAdapter) RefreshCredential

func (m *MockAdapter) RefreshCredential(ctx context.Context, cred *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(infos []models.ModelInfo) *MockAdapter

WithModelInfos configures the GetModelInfos behavior.

func (*MockAdapter) WithValidateFunc

func (m *MockAdapter) WithValidateFunc(f func(map[string]any) error) *MockAdapter

WithValidateFunc configures the ValidateCredentials behavior.

Jump to

Keyboard shortcuts

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