testutil

package
v1.0.60 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testutil provides shared testing utilities, mocks, and fixtures for use across the ai-provider-kit test suite.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigurableMockProvider

type ConfigurableMockProvider struct {
	// contains filtered or unexported fields
}

ConfigurableMockProvider is a mock Provider implementation with configurable behavior. It allows tests to simulate various provider responses and scenarios.

func NewConfigurableMockProvider

func NewConfigurableMockProvider(name string, providerType types.ProviderType) *ConfigurableMockProvider

NewConfigurableMockProvider creates a new mock provider with default settings.

func (*ConfigurableMockProvider) Authenticate

func (m *ConfigurableMockProvider) Authenticate(ctx context.Context, config types.AuthConfig) error

func (*ConfigurableMockProvider) Configure

func (m *ConfigurableMockProvider) Configure(config types.ProviderConfig) error

func (*ConfigurableMockProvider) CreateResponse

func (*ConfigurableMockProvider) CreateStream

func (*ConfigurableMockProvider) Description

func (m *ConfigurableMockProvider) Description() string

func (*ConfigurableMockProvider) GenerateChatCompletion

func (m *ConfigurableMockProvider) GenerateChatCompletion(ctx context.Context, options types.GenerateOptions) (types.ChatCompletionStream, error)

func (*ConfigurableMockProvider) GetAuthenticateCallCount

func (m *ConfigurableMockProvider) GetAuthenticateCallCount() int

GetAuthenticateCallCount returns the number of times Authenticate was called

func (*ConfigurableMockProvider) GetConfig

func (*ConfigurableMockProvider) GetDefaultModel

func (m *ConfigurableMockProvider) GetDefaultModel() string

func (*ConfigurableMockProvider) GetGenerateChatCallCount

func (m *ConfigurableMockProvider) GetGenerateChatCallCount() int

GetGenerateChatCallCount returns the number of times GenerateChatCompletion was called

func (*ConfigurableMockProvider) GetHealthCheckCallCount

func (m *ConfigurableMockProvider) GetHealthCheckCallCount() int

GetHealthCheckCallCount returns the number of times HealthCheck was called

func (*ConfigurableMockProvider) GetMetrics

func (*ConfigurableMockProvider) GetModels

func (m *ConfigurableMockProvider) GetModels(ctx context.Context) ([]types.Model, error)

func (*ConfigurableMockProvider) GetToolFormat

func (m *ConfigurableMockProvider) GetToolFormat() string

func (*ConfigurableMockProvider) HealthCheck

func (m *ConfigurableMockProvider) HealthCheck(ctx context.Context) error

func (*ConfigurableMockProvider) InvokeServerTool

func (m *ConfigurableMockProvider) InvokeServerTool(ctx context.Context, toolName string, params interface{}) (interface{}, error)

func (*ConfigurableMockProvider) IsAuthenticated

func (m *ConfigurableMockProvider) IsAuthenticated() bool

func (*ConfigurableMockProvider) Logout

func (*ConfigurableMockProvider) Name

func (m *ConfigurableMockProvider) Name() string

func (*ConfigurableMockProvider) SetAuthenticateError

func (m *ConfigurableMockProvider) SetAuthenticateError(err error)

SetAuthenticateError configures the provider to return an error on Authenticate

func (*ConfigurableMockProvider) SetChatCompletionStream

func (m *ConfigurableMockProvider) SetChatCompletionStream(stream types.ChatCompletionStream)

SetChatCompletionStream configures the stream returned by GenerateChatCompletion

func (*ConfigurableMockProvider) SetGenerateError

func (m *ConfigurableMockProvider) SetGenerateError(err error)

SetGenerateError configures the provider to return an error on GenerateChatCompletion

func (*ConfigurableMockProvider) SetGetModelsError

func (m *ConfigurableMockProvider) SetGetModelsError(err error)

SetGetModelsError configures the provider to return an error on GetModels

func (*ConfigurableMockProvider) SetHealthCheckError

func (m *ConfigurableMockProvider) SetHealthCheckError(err error)

SetHealthCheckError configures the provider to return an error on HealthCheck

func (*ConfigurableMockProvider) SetModels

func (m *ConfigurableMockProvider) SetModels(models []types.Model)

SetModels configures the list of models returned by GetModels

func (*ConfigurableMockProvider) SupportsResponsesAPI

func (m *ConfigurableMockProvider) SupportsResponsesAPI() bool

func (*ConfigurableMockProvider) SupportsStreaming

func (m *ConfigurableMockProvider) SupportsStreaming() bool

func (*ConfigurableMockProvider) SupportsToolCalling

func (m *ConfigurableMockProvider) SupportsToolCalling() bool

func (*ConfigurableMockProvider) Type

type ConfigurableMockStream

type ConfigurableMockStream struct {
	// contains filtered or unexported fields
}

ConfigurableMockStream is a mock ChatCompletionStream implementation with configurable behavior.

func NewConfigurableMockStream

func NewConfigurableMockStream(chunks []types.ChatCompletionChunk) *ConfigurableMockStream

NewConfigurableMockStream creates a new mock stream with the given chunks.

func (*ConfigurableMockStream) Close

func (s *ConfigurableMockStream) Close() error

Close resets the stream to the beginning.

func (*ConfigurableMockStream) Next

Next returns the next chunk from the stream.

func (*ConfigurableMockStream) Reset

func (s *ConfigurableMockStream) Reset()

Reset resets the stream to the beginning without locking (useful in tests).

func (*ConfigurableMockStream) SetError

func (s *ConfigurableMockStream) SetError(err error)

SetError configures the stream to return an error on the next Next() call.

type TestFixtures

type TestFixtures struct {
	// Provider configurations
	OpenAIConfig    types.ProviderConfig
	AnthropicConfig types.ProviderConfig
	GeminiConfig    types.ProviderConfig
	QwenConfig      types.ProviderConfig
	CerebrasConfig  types.ProviderConfig

	// Auth configurations
	APIKeyAuth types.AuthConfig
	OAuthAuth  types.AuthConfig

	// Messages
	SimpleMessage       types.ChatMessage
	SystemMessage       types.ChatMessage
	ToolCallMessage     types.ChatMessage
	ToolResponseMessage types.ChatMessage
	MultiTurnMessages   []types.ChatMessage

	// Tools
	WeatherTool    types.Tool
	CalculatorTool types.Tool
	SearchTool     types.Tool
	AllTools       []types.Tool

	// Tool calls
	WeatherToolCall    types.ToolCall
	CalculatorToolCall types.ToolCall

	// Models
	OpenAIModels    []types.Model
	AnthropicModels []types.Model
	GeminiModels    []types.Model

	// Responses
	StandardResponse     types.StandardResponse
	StreamChunks         []types.ChatCompletionChunk
	StandardStreamChunks []types.StandardStreamChunk

	// Generate options
	BasicGenerateOptions       types.GenerateOptions
	StreamingGenerateOptions   types.GenerateOptions
	ToolCallingGenerateOptions types.GenerateOptions

	// Standard requests
	BasicRequest       types.StandardRequest
	StreamingRequest   types.StandardRequest
	ToolCallingRequest types.StandardRequest
}

TestFixtures provides common test data and fixtures for use across tests.

func NewTestFixtures

func NewTestFixtures() *TestFixtures

NewTestFixtures creates a new TestFixtures instance with all standard test data.

func (*TestFixtures) NewGenerateOptions

func (f *TestFixtures) NewGenerateOptions(messages []types.ChatMessage, model string) types.GenerateOptions

NewGenerateOptions creates new generate options with sensible defaults.

func (*TestFixtures) NewMessage

func (f *TestFixtures) NewMessage(role, content string) types.ChatMessage

NewMessage creates a new chat message with the given role and content.

func (*TestFixtures) NewProviderConfig

func (f *TestFixtures) NewProviderConfig(providerType types.ProviderType, apiKey string) types.ProviderConfig

NewProviderConfig creates a custom provider configuration based on a template.

func (*TestFixtures) NewToolCall

func (f *TestFixtures) NewToolCall(id, name, arguments string) types.ToolCall

NewToolCall creates a new tool call with the given parameters.

Jump to

Keyboard shortcuts

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