testutil

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const TestAPIKey = "test-binary-api-key-12345"

TestAPIKey is the fixed API key used in binary tests

Variables

This section is empty.

Functions

func CheckJSONResponse

func CheckJSONResponse(resp *http.Response) error

CheckJSONResponse checks if a response contains valid JSON

func ParseJSONResponse

func ParseJSONResponse(resp *http.Response, result interface{}) error

ParseJSONResponse parses a JSON response into the given interface

func ParseJSONToString

func ParseJSONToString(data interface{}) (string, error)

ParseJSONToString converts an interface to a JSON string

func ReadResponseBody

func ReadResponseBody(resp *http.Response) (string, error)

ReadResponseBody reads the entire response body as a string

Types

type APIResponse

type APIResponse struct {
	Success bool        `json:"success"`
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
}

APIResponse represents a standard API response

func ExpectAPISuccess

func ExpectAPISuccess(resp *http.Response) (*APIResponse, error)

ExpectAPISuccess checks that an API response indicates success

func ParseAPIResponse

func ParseAPIResponse(resp *http.Response) (*APIResponse, error)

ParseAPIResponse parses a standard API response

type BinaryTestEnv

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

BinaryTestEnv manages a test environment with the actual mcpproxy binary

func NewBinaryTestEnv

func NewBinaryTestEnv(t *testing.T) *BinaryTestEnv

NewBinaryTestEnv creates a new binary test environment

func (*BinaryTestEnv) CallMCPTool

func (env *BinaryTestEnv) CallMCPTool(toolName string, args map[string]interface{}) ([]byte, error)

CallMCPTool calls an MCP tool through the proxy using the MCP client library

func (*BinaryTestEnv) Cleanup

func (env *BinaryTestEnv) Cleanup()

Cleanup cleans up the test environment

func (*BinaryTestEnv) GetAPIURL

func (env *BinaryTestEnv) GetAPIURL() string

GetAPIURL returns the API base URL of the test server

func (*BinaryTestEnv) GetBaseURL

func (env *BinaryTestEnv) GetBaseURL() string

GetBaseURL returns the base URL of the test server

func (*BinaryTestEnv) GetConfigPath

func (env *BinaryTestEnv) GetConfigPath() string

GetConfigPath returns the path to the test config file

func (*BinaryTestEnv) GetHTTPClient

func (env *BinaryTestEnv) GetHTTPClient() *HTTPClient

GetHTTPClient returns an HTTP client configured with the test API key

func (*BinaryTestEnv) GetPort

func (env *BinaryTestEnv) GetPort() int

GetPort returns the port the server is running on

func (*BinaryTestEnv) InitializeMCPSession

func (env *BinaryTestEnv) InitializeMCPSession()

InitializeMCPSession initializes an MCP session with the server using the MCP client library

func (*BinaryTestEnv) Start

func (env *BinaryTestEnv) Start()

Start starts the mcpproxy binary

func (*BinaryTestEnv) WaitForEverythingServer

func (env *BinaryTestEnv) WaitForEverythingServer()

WaitForEverythingServer waits for the test server to connect and be ready

func (*BinaryTestEnv) WaitForReady

func (env *BinaryTestEnv) WaitForReady()

WaitForReady waits for the server to be ready to accept requests

type HTTPClient

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

HTTPClient wraps http.Client with convenience methods for testing

func NewHTTPClient

func NewHTTPClient(baseURL string) *HTTPClient

NewHTTPClient creates a new HTTP client for testing

func NewHTTPClientWithAPIKey

func NewHTTPClientWithAPIKey(baseURL string, apiKey string) *HTTPClient

NewHTTPClientWithAPIKey creates a new HTTP client with API key authentication

func (*HTTPClient) Get

func (c *HTTPClient) Get(path string) (*http.Response, error)

Get performs a GET request

func (*HTTPClient) GetJSON

func (c *HTTPClient) GetJSON(path string, result interface{}) error

GetJSON performs a GET request and parses JSON response

func (*HTTPClient) Post

func (c *HTTPClient) Post(path string, body io.Reader) (*http.Response, error)

Post performs a POST request

func (*HTTPClient) PostJSON

func (c *HTTPClient) PostJSON(path string, data interface{}) (*http.Response, error)

PostJSON performs a POST request with JSON data

func (*HTTPClient) PostJSONExpectStatus

func (c *HTTPClient) PostJSONExpectStatus(path string, data interface{}, expectedStatus int) (*http.Response, error)

PostJSONExpectStatus performs a POST request and checks the status code

type MCPCallRequest

type MCPCallRequest struct {
	ToolName string                 `json:"name"`
	Args     map[string]interface{} `json:"args"`
}

MCPCallRequest represents an MCP call_tool request

type SSEReader

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

SSEReader reads Server-Sent Events

func NewSSEReader

func NewSSEReader(resp *http.Response) *SSEReader

NewSSEReader creates a new SSE reader

func (*SSEReader) Close

func (r *SSEReader) Close() error

Close closes the SSE reader

func (*SSEReader) ReadEvent

func (r *SSEReader) ReadEvent(timeout time.Duration) (map[string]string, error)

ReadEvent reads a single SSE event

type TestLogEntry

type TestLogEntry struct {
	Timestamp string                 `json:"timestamp"`
	Level     string                 `json:"level"`
	Message   string                 `json:"message"`
	Server    string                 `json:"server,omitempty"`
	Fields    map[string]interface{} `json:"fields,omitempty"`
}

TestLogEntry represents a single log entry

type TestSearchResults

type TestSearchResults struct {
	Success bool `json:"success"`
	Data    struct {
		Query   string           `json:"query"`
		Results []TestSearchTool `json:"results"`
	} `json:"data"`
}

TestSearchResults represents search results

type TestSearchTool

type TestSearchTool struct {
	Name        string  `json:"name"`
	Description string  `json:"description"`
	Server      string  `json:"server"`
	Score       float64 `json:"score"`
}

TestSearchTool represents a search result tool

type TestServer

type TestServer struct {
	Name             string `json:"name"`
	Protocol         string `json:"protocol"`
	Enabled          bool   `json:"enabled"`
	Quarantined      bool   `json:"quarantined"`
	Connected        bool   `json:"connected"`
	Connecting       bool   `json:"connecting"`
	ToolCount        int    `json:"tool_count"`
	LastError        string `json:"last_error"`
	ConnectionStatus string `json:"connection_status,omitempty"`
}

TestServer represents a server in the test environment

type TestServerList

type TestServerList struct {
	Success bool `json:"success"`
	Data    struct {
		Servers []TestServer `json:"servers"`
	} `json:"data"`
}

TestServerList represents a simplified server list response

type TestServerLogsResponse

type TestServerLogsResponse struct {
	Success bool `json:"success"`
	Data    struct {
		ServerName string         `json:"server_name"`
		Logs       []TestLogEntry `json:"logs"`
		Count      int            `json:"count"`
	} `json:"data"`
}

TestServerLogsResponse represents a server logs response

type TestTool

type TestTool struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

TestTool represents a tool in the test environment

type TestToolList

type TestToolList struct {
	Success bool `json:"success"`
	Data    struct {
		Server string     `json:"server"`
		Tools  []TestTool `json:"tools"`
	} `json:"data"`
}

TestToolList represents a tool list response

Jump to

Keyboard shortcuts

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