tests

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MPL-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertJSONResponse

func AssertJSONResponse(t *testing.T, resp *http.Response, expectedStatus int, checkFields func(map[string]interface{}))

AssertJSONResponse asserts that the response is valid JSON and checks specific fields

func CaptureRequest

func CaptureRequest(handler gin.HandlerFunc) (*http.Request, map[string]interface{}, error)

CaptureRequest captures HTTP request details

func Cleanup

func Cleanup()

Cleanup removes test files

func CreateJSONBody

func CreateJSONBody(data interface{}) *bytes.Buffer

CreateJSONBody creates a JSON body for HTTP requests

func CreateMockChatCompletionResponse

func CreateMockChatCompletionResponse(id, model, content string) map[string]interface{}

CreateMockChatCompletionResponse creates a mock chat completion response that matches OpenAI format

func CreateMockChatCompletionResponseWithToolCalls

func CreateMockChatCompletionResponseWithToolCalls(id, model, content string, toolCalls []map[string]interface{}) map[string]interface{}

CreateMockChatCompletionResponseWithToolCalls creates a mock response with function/tool calls

func CreateTestChatRequest

func CreateTestChatRequest(model string, messages []map[string]string) map[string]interface{}

CreateTestChatRequest creates a test chat completion request

func CreateTestMessage

func CreateTestMessage(role, content string) map[string]string

CreateTestMessage creates a test message

func CreateTestProvider

func CreateTestProvider(name, apiBase, token string) *typ.Provider

CreateTestProvider creates a test provider configuration

func FindGoModRoot

func FindGoModRoot() (string, error)

func RunMockProviderTests

func RunMockProviderTests(t *testing.T)

RunMockProviderTests runs all mock provider tests

Types

type MockProviderServer

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

MockProviderServer represents a mock AI provider server

func NewMockProviderServer

func NewMockProviderServer() *MockProviderServer

NewMockProviderServer creates a new mock provider server

func (*MockProviderServer) Close

func (m *MockProviderServer) Close()

Close closes the mock server

func (*MockProviderServer) GetCallCount

func (m *MockProviderServer) GetCallCount(endpoint string) int

GetCallCount returns the number of calls to an endpoint

func (*MockProviderServer) GetLastRequest

func (m *MockProviderServer) GetLastRequest(endpoint string) map[string]interface{}

GetLastRequest returns the last request body for an endpoint

func (*MockProviderServer) GetURL

func (m *MockProviderServer) GetURL() string

GetURL returns the mock server URL

func (*MockProviderServer) Reset

func (m *MockProviderServer) Reset()

Reset resets call counts and request history

func (*MockProviderServer) SetResponse

func (m *MockProviderServer) SetResponse(endpoint string, response MockResponse)

SetResponse configures a mock response for a specific endpoint

func (*MockProviderServer) SetStreamingResponse

func (m *MockProviderServer) SetStreamingResponse(endpoint string, response MockStreamingResponse)

SetStreamingResponse configures a mock streaming response for a specific endpoint

type MockProviderTestSuite

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

MockProviderTestSuite provides a comprehensive test suite for provider testing

func NewMockProviderTestSuite

func NewMockProviderTestSuite(t *testing.T) *MockProviderTestSuite

NewMockProviderTestSuite creates a new test suite

func (*MockProviderTestSuite) Cleanup

func (suite *MockProviderTestSuite) Cleanup()

Cleanup cleans up the test suite

func (*MockProviderTestSuite) TestInvalidRequest

func (suite *MockProviderTestSuite) TestInvalidRequest()

TestInvalidRequest tests handling of invalid requests

func (*MockProviderTestSuite) TestNetworkTimeout

func (suite *MockProviderTestSuite) TestNetworkTimeout()

TestNetworkTimeout tests timeout handling

func (*MockProviderTestSuite) TestProviderError

func (suite *MockProviderTestSuite) TestProviderError()

TestProviderError tests error handling from provider

func (*MockProviderTestSuite) TestRequestForwarding

func (suite *MockProviderTestSuite) TestRequestForwarding()

TestRequestForwarding verifies correct request forwarding to provider

func (*MockProviderTestSuite) TestSuccessfulRequest

func (suite *MockProviderTestSuite) TestSuccessfulRequest()

TestSuccessfulRequest tests a successful chat completion request

type MockResponse

type MockResponse struct {
	StatusCode int
	Body       interface{}
	Delay      time.Duration
	Error      string
}

MockResponse defines a mock response configuration

type MockStreamingResponse

type MockStreamingResponse struct {
	Events []string
}

MockStreamingResponse defines a mock streaming response configuration

type TestConfigDir

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

TestConfigDir represents a temporary config directory for testing

func NewTestConfigDirCopy

func NewTestConfigDirCopy(t *testing.T) *TestConfigDir

NewTestConfigDirCopy creates a temporary copy of the real config directory for testing purposes. It automatically cleans up the temporary directory when the test finishes.

func (*TestConfigDir) Path

func (td *TestConfigDir) Path() string

Path returns the path to the temporary config directory

type TestServer

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

TestServer represents a test server wrapper

func NewTestServer

func NewTestServer(t *testing.T) *TestServer

NewTestServer creates a new test server

func NewTestServerWithAdaptor

func NewTestServerWithAdaptor(t *testing.T) *TestServer

NewTestServerWithAdaptor creates a new test server with adaptor flag

func NewTestServerWithAdaptorFromConfig

func NewTestServerWithAdaptorFromConfig(appConfig *config.AppConfig) *TestServer

NewTestServerWithAdaptorFromConfig creates a new test server with adaptor flag using existing app config

func NewTestServerWithConfigDir

func NewTestServerWithConfigDir(t *testing.T, configDir string) *TestServer

NewTestServer creates a new test server with custom config directory

func (*TestServer) AddTestProvider

func (ts *TestServer) AddTestProvider(t *testing.T, name, apiBase, apiStyle string, enabled bool)

AddTestProvider adds a single test provider

func (*TestServer) AddTestProviderWithURL

func (ts *TestServer) AddTestProviderWithURL(t *testing.T, name, url, apiStyle string, enabled bool)

AddTestProviderWithURL adds a provider with a specific URL

func (*TestServer) AddTestProviders

func (ts *TestServer) AddTestProviders(t *testing.T)

AddTestProviders adds test providers to the configuration

func (*TestServer) AddTestRule

func (ts *TestServer) AddTestRule(t *testing.T, requestModel, providerName, model string)

AddTestRule adds a test rule that routes to a specific provider

func (*TestServer) GetProviderToken

func (ts *TestServer) GetProviderToken(uid string, isRealConfig bool) string

GetProviderToken returns the appropriate token for Anthropic API requests

Jump to

Keyboard shortcuts

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