testutils

package
v0.59.5 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t *testing.T, expected, actual any)

AssertEqual fails the test if expected != actual

func AssertError

func AssertError(t *testing.T, err error)

AssertError fails the test if err is nil

func AssertErrorContains

func AssertErrorContains(t *testing.T, err error, expected string)

AssertErrorContains fails the test if err is nil or doesn't contain the expected message

func AssertFalse added in v0.21.1

func AssertFalse(t *testing.T, condition bool)

AssertFalse fails the test if condition is true

func AssertNil added in v0.33.2

func AssertNil(t *testing.T, value any)

AssertNil asserts that a value is nil AssertNil asserts that a value is nil AssertNil asserts that a value is nil

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError fails the test if err is not nil

func AssertNotNil

func AssertNotNil(t *testing.T, value any)

AssertNotNil fails the test if value is nil

func AssertTrue added in v0.21.1

func AssertTrue(t *testing.T, condition bool)

AssertTrue fails the test if condition is false

func Contains

func Contains(s, substr string) bool

Contains checks if a string contains a substring

func CreateTestCache

func CreateTestCache() *sync.Map

CreateTestCache creates a cache suitable for testing

func CreateTestContext

func CreateTestContext() context.Context

CreateTestContext creates a context suitable for testing

func CreateTestLogger

func CreateTestLogger() *logrus.Logger

CreateTestLogger creates a logger suitable for testing

func ExtractPackageVersions added in v0.28.0

func ExtractPackageVersions(t *testing.T, result any) []packageversions.PackageVersion

ExtractPackageVersions extracts PackageVersion structs from a tool result

func WithEnv added in v0.50.5

func WithEnv(t *testing.T, key, value string) func()

WithEnv sets an environment variable for the duration of a test and returns a cleanup function. Usage:

cleanup := testutils.WithEnv(t, "ENABLE_ADDITIONAL_TOOLS", "tool-name")
defer cleanup()

func WithEnvUnset added in v0.50.5

func WithEnvUnset(t *testing.T, key string) func()

WithEnvUnset unsets an environment variable for the duration of a test and returns a cleanup function. Usage:

defer testutils.WithEnvUnset(t, "ENABLE_ADDITIONAL_TOOLS")()

Types

type MockCache

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

MockCache provides a controllable cache for testing

func NewMockCache

func NewMockCache() *MockCache

NewMockCache creates a new mock cache

func (*MockCache) Delete

func (m *MockCache) Delete(key any)

Delete removes a value from the mock cache

func (*MockCache) Load

func (m *MockCache) Load(key any) (any, bool)

Load loads a value from the mock cache

func (*MockCache) Range

func (m *MockCache) Range(f func(key, value any) bool)

Range calls f sequentially for each key and value present in the cache

func (*MockCache) Store

func (m *MockCache) Store(key, value any)

Store stores a value in the mock cache

type MockHTTPClient

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

MockHTTPClient for testing HTTP-based tools

func NewMockHTTPClient

func NewMockHTTPClient() *MockHTTPClient

NewMockHTTPClient creates a new mock HTTP client

func (*MockHTTPClient) GetWithContext added in v0.56.0

func (m *MockHTTPClient) GetWithContext(ctx context.Context, url string) (*http.Response, error)

GetWithContext simulates an HTTP GET request with context support (implements shadcnui.HTTPClient interface)

func (*MockHTTPClient) WithError

func (m *MockHTTPClient) WithError(err error) *MockHTTPClient

WithError configures the mock to return an error

func (*MockHTTPClient) WithResponse

func (m *MockHTTPClient) WithResponse(url string, statusCode int, body string) *MockHTTPClient

WithResponse configures a response for a specific URL

type MockHTTPResponse

type MockHTTPResponse struct {
	StatusCode int
	Body       string
	Headers    map[string]string
}

MockHTTPResponse simulates an HTTP response

type MockReadCloser

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

MockReadCloser implements io.ReadCloser for mock responses

func (*MockReadCloser) Close

func (m *MockReadCloser) Close() error

Close implements io.Closer

func (*MockReadCloser) Read

func (m *MockReadCloser) Read(p []byte) (n int, err error)

Read implements io.Reader

type MockTool

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

MockTool implements the Tool interface for testing

func NewMockTool

func NewMockTool(name string) *MockTool

NewMockTool creates a new mock tool

func (*MockTool) Definition

func (m *MockTool) Definition() mcp.Tool

Definition returns the tool's definition for MCP registration

func (*MockTool) Execute

func (m *MockTool) Execute(ctx context.Context, logger *logrus.Logger, cache *sync.Map, args map[string]any) (*mcp.CallToolResult, error)

Execute executes the mock tool

func (*MockTool) WithError

func (m *MockTool) WithError(err error) *MockTool

WithError configures the mock to return an error

func (*MockTool) WithResult

func (m *MockTool) WithResult(result *mcp.CallToolResult) *MockTool

WithResult configures the mock to return a specific result

Jump to

Keyboard shortcuts

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