integration

package
v0.0.0-...-be7b520 Latest Latest
Warning

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

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

Documentation

Overview

Package integration contains integration tests and helpers

Index

Constants

View Source
const (
	// McpAnyServerStartupTimeout is the timeout for the server to start.
	McpAnyServerStartupTimeout = 300 * time.Second
	// ServiceStartupTimeout is the timeout for services to start up.
	ServiceStartupTimeout = 120 * time.Second
	// TestWaitTimeShort is a short wait time for tests.
	TestWaitTimeShort = 120 * time.Second
	// TestWaitTimeMedium is the default timeout for medium duration tests.
	TestWaitTimeMedium = 480 * time.Second
	// TestWaitTimeLong is the default timeout for long duration tests.
	TestWaitTimeLong = 10 * time.Minute
	// RetryInterval is the interval between retries.
	RetryInterval = 250 * time.Millisecond

	// LoopbackIP is the default loopback IP for testing.
	LoopbackIP = "127.0.0.1"
)

Variables

This section is empty.

Functions

func CreateTempConfigFile

func CreateTempConfigFile(t *testing.T, config *configv1.UpstreamServiceConfig) string

CreateTempConfigFile creates a temporary configuration file for the configured upstream service.

t is the t. config holds the configuration settings.

Returns the result.

func CreateTempNatsConfigFile

func CreateTempNatsConfigFile(t *testing.T) string

CreateTempNatsConfigFile creates a temporary configuration file for NATS.

t is the t.

Returns the result.

func FindFreePort

func FindFreePort(t *testing.T) int

FindFreePort finds a free TCP port on localhost.

t is the t.

Returns the result.

func GetProjectRoot

func GetProjectRoot() (string, error)

GetProjectRoot returns the absolute path to the project root.

Returns the result. Returns an error if the operation fails.

func IsDockerSocketAccessible

func IsDockerSocketAccessible() bool

IsDockerSocketAccessible checks if the Docker daemon is accessible.

Returns true if successful.

func ProjectRoot

func ProjectRoot(t *testing.T) string

ProjectRoot returns the absolute path to the project root.

t is the t.

Returns the result.

func RegisterGRPCService

func RegisterGRPCService(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, grpcTargetAddress string, authConfig *configv1.Authentication)

RegisterGRPCService registers a gRPC service.

t is the t. regClient is the regClient. serviceID is the serviceID. grpcTargetAddress is the grpcTargetAddress. authConfig is the authConfig.

func RegisterHTTPService

func RegisterHTTPService(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, baseURL, operationID, endpointPath, httpMethod string, authConfig *configv1.Authentication)

RegisterHTTPService registers a simple HTTP service.

t is the t. regClient is the regClient. serviceID is the serviceID. baseURL is the baseURL. operationID is the operationID. endpointPath is the endpointPath. httpMethod is the httpMethod. authConfig is the authConfig.

func RegisterHTTPServiceWithJSONRPC

func RegisterHTTPServiceWithJSONRPC(t *testing.T, mcpanyEndpoint, serviceID, baseURL, operationID, endpointPath, httpMethod string, authConfig *configv1.Authentication)

RegisterHTTPServiceWithJSONRPC registers an HTTP service using the JSON-RPC endpoint.

t is the t. mcpanyEndpoint is the mcpanyEndpoint. serviceID is the serviceID. baseURL is the baseURL. operationID is the operationID. endpointPath is the endpointPath. httpMethod is the httpMethod. authConfig is the authConfig.

func RegisterHTTPServiceWithParams

func RegisterHTTPServiceWithParams(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, baseURL string, toolDef *configv1.ToolDefinition, endpointPath, httpMethod string, params []*configv1.HttpParameterMapping, authConfig *configv1.Authentication)

RegisterHTTPServiceWithParams registers an HTTP service with parameters.

t is the t. regClient is the regClient. serviceID is the serviceID. baseURL is the baseURL. toolDef is the toolDef. endpointPath is the endpointPath. httpMethod is the httpMethod. params is the params. authConfig is the authConfig.

func RegisterOpenAPIService

func RegisterOpenAPIService(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, openAPISpecPath, serverURLOverride string, authConfig *configv1.Authentication)

RegisterOpenAPIService registers an OpenAPI service.

t is the t. regClient is the regClient. serviceID is the serviceID. openAPISpecPath is the openAPISpecPath. serverURLOverride is the serverURLOverride. authConfig is the authConfig.

func RegisterServiceViaAPI

func RegisterServiceViaAPI(t *testing.T, regClient apiv1.RegistrationServiceClient, req *apiv1.RegisterServiceRequest)

RegisterServiceViaAPI registers a service using the gRPC API.

t is the t. regClient is the regClient. req is the request object.

func RegisterStdioMCPService

func RegisterStdioMCPService(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, command string, toolAutoDiscovery bool)

RegisterStdioMCPService registers an MCP service using stdio.

t is the t. regClient is the regClient. serviceID is the serviceID. command is the command. toolAutoDiscovery is the toolAutoDiscovery.

func RegisterStdioService

func RegisterStdioService(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, commandName string, toolAutoDiscovery bool, commandArgs ...string)

RegisterStdioService registers a raw stdio service.

t is the t. regClient is the regClient. serviceID is the serviceID. commandName is the commandName. toolAutoDiscovery is the toolAutoDiscovery. commandArgs is the commandArgs.

func RegisterStdioServiceWithSetup

func RegisterStdioServiceWithSetup(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, commandName string, toolAutoDiscovery bool, workingDir, containerImage string, setupCommands []string, env map[string]string, commandArgs ...string)

RegisterStdioServiceWithSetup registers a stdio service with setup steps.

t is the t. regClient is the regClient. serviceID is the serviceID. commandName is the commandName. toolAutoDiscovery is the toolAutoDiscovery. workingDir is the workingDir. containerImage is the containerImage. setupCommands is the setupCommands. env is the env. commandArgs is the commandArgs.

func RegisterStreamableMCPService

func RegisterStreamableMCPService(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, targetURL string, toolAutoDiscovery bool, authConfig *configv1.Authentication)

RegisterStreamableMCPService registers a streamable MCP service (SSE).

t is the t. regClient is the regClient. serviceID is the serviceID. targetURL is the targetURL. toolAutoDiscovery is the toolAutoDiscovery. authConfig is the authConfig.

func RegisterWebrtcService

func RegisterWebrtcService(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, baseURL, operationID string, authConfig *configv1.Authentication)

RegisterWebrtcService registers a WebRTC service.

t is the t. regClient is the regClient. serviceID is the serviceID. baseURL is the baseURL. operationID is the operationID. authConfig is the authConfig.

func RegisterWebsocketService

func RegisterWebsocketService(t *testing.T, regClient apiv1.RegistrationServiceClient, serviceID, baseURL, operationID string, authConfig *configv1.Authentication)

RegisterWebsocketService registers a WebSocket service.

t is the t. regClient is the regClient. serviceID is the serviceID. baseURL is the baseURL. operationID is the operationID. authConfig is the authConfig.

func StartDockerContainer

func StartDockerContainer(t *testing.T, imageName, containerName string, runArgs []string, command ...string) (cleanupFunc func())

StartDockerContainer starts a docker container with the given image and args.

t is the t. imageName is the imageName. containerName is the containerName. runArgs is the runArgs. command is the command.

Returns the result.

func StartNatsServer

func StartNatsServer(t *testing.T) (string, func())

StartNatsServer starts a NATS server for testing.

t is the t.

Returns the result. Returns the result.

func StartRedisContainer

func StartRedisContainer(t *testing.T) (redisAddr string, cleanupFunc func())

StartRedisContainer starts a Redis container for testing. StartRedisContainer starts a Redis container for testing.

func WaitForGRPCReady

func WaitForGRPCReady(t *testing.T, grpcAddress string, timeout time.Duration)

WaitForGRPCReady waits for a gRPC server to become ready by attempting to connect.

t is the t. grpcAddress is the grpcAddress. timeout is the timeout.

func WaitForHTTPHealth

func WaitForHTTPHealth(t *testing.T, url string, timeout time.Duration)

WaitForHTTPHealth waits for an HTTP endpoint to return a 200 OK status.

t is the t. url is the url. timeout is the timeout.

func WaitForPortFromLogs

func WaitForPortFromLogs(t *testing.T, mp *ManagedProcess, serverName string) (string, error)

WaitForPortFromLogs waits for a log line indicating the server is listening and extracts the address.

t is the t. mp is the mp. serverName is the serverName.

Returns the result. Returns an error if the operation fails.

func WaitForTCPPort

func WaitForTCPPort(t *testing.T, port int, timeout time.Duration)

WaitForTCPPort waits for a TCP port to become open and accepting connections.

t is the t. port is the port. timeout is the timeout.

func WaitForWebsocketReady

func WaitForWebsocketReady(t *testing.T, url string, timeout time.Duration)

WaitForWebsocketReady waits for a websocket server to become ready by attempting to connect.

t is the t. url is the url. timeout is the timeout.

Types

type MCPANYTestServerInfo

type MCPANYTestServerInfo struct {
	Process                  *ManagedProcess
	JSONRPCEndpoint          string
	HTTPEndpoint             string
	GrpcRegistrationEndpoint string
	MetricsEndpoint          string
	NatsURL                  string
	SessionID                string
	HTTPClient               *http.Client
	GRPCRegConn              *grpc.ClientConn
	RegistrationClient       apiv1.RegistrationServiceClient
	CleanupFunc              func()
	T                        *testing.T
}

MCPANYTestServerInfo contains information about a running MCPANY test server. --- MCPANY Server Helper (External Process) --- MCPANYTestServerInfo contains information about a running MCP Any server instance for testing.

func StartInProcessMCPANYServer

func StartInProcessMCPANYServer(t *testing.T, _ string, apiKey ...string) *MCPANYTestServerInfo

StartInProcessMCPANYServer starts an in-process MCP Any server for testing.

t is the t. _ is an unused parameter. apiKey is the apiKey.

Returns the result.

func StartMCPANYServer

func StartMCPANYServer(t *testing.T, testName string, extraArgs ...string) *MCPANYTestServerInfo

StartMCPANYServer starts the MCP Any server with default settings.

t is the t. testName is the testName. extraArgs is the extraArgs.

Returns the result.

func StartMCPANYServerWithClock

func StartMCPANYServerWithClock(t *testing.T, testName string, healthCheck bool, extraArgs ...string) *MCPANYTestServerInfo

StartMCPANYServerWithClock starts the MCP Any server, optionally waiting for health.

t is the t. testName is the testName. healthCheck is the healthCheck. extraArgs is the extraArgs.

Returns the result.

func StartMCPANYServerWithConfig

func StartMCPANYServerWithConfig(t *testing.T, testName, configContent string) *MCPANYTestServerInfo

StartMCPANYServerWithConfig starts the MCP Any server with a provided config content.

t is the t. testName is the testName. configContent is the configContent.

Returns the result.

func StartMCPANYServerWithNoHealthCheck

func StartMCPANYServerWithNoHealthCheck(t *testing.T, testName string, extraArgs ...string) *MCPANYTestServerInfo

StartMCPANYServerWithNoHealthCheck starts the MCP Any server but skips the health check.

t is the t. testName is the testName. extraArgs is the extraArgs.

Returns the result.

func (*MCPANYTestServerInfo) CallTool

CallTool calls tools/call via JSON-RPC.

ctx is the context for the request. params is the params.

Returns the result. Returns an error if the operation fails.

func (*MCPANYTestServerInfo) Initialize

func (s *MCPANYTestServerInfo) Initialize(ctx context.Context) error

Initialize performs the MCP initialization handshake.

ctx is the context for the request.

Returns an error if the operation fails.

func (*MCPANYTestServerInfo) ListTools

ListTools calls tools/list via JSON-RPC.

ctx is the context for the request.

Returns the result. Returns an error if the operation fails.

type MCPJSONRPCError

type MCPJSONRPCError struct {
	// Code is the error code.
	Code int `json:"code"`
	// Message is the error message.
	Message string `json:"message"`
	// Data is optional additional error data.
	Data interface{} `json:"data,omitempty"`
}

MCPJSONRPCError represents a JSON-RPC error.

func (*MCPJSONRPCError) Error

func (e *MCPJSONRPCError) Error() string

Error implements the error interface.

Returns the result.

type ManagedProcess

type ManagedProcess struct {
	IgnoreExitStatusOne bool
	Port                int
	Dir                 string
	// contains filtered or unexported fields
}

ManagedProcess represents an external process managed by the test framework. --- Process Management for External Services --- ManagedProcess manages an external process for testing.

func NewManagedProcess

func NewManagedProcess(t *testing.T, label, command string, args []string, env []string) *ManagedProcess

NewManagedProcess creates a new ManagedProcess instance.

t is the t. label is the label. command is the command. args is the args. env is the env.

Returns the result.

func (*ManagedProcess) Cmd

func (mp *ManagedProcess) Cmd() *exec.Cmd

Cmd returns the underlying exec.Cmd.

Returns the result.

func (*ManagedProcess) Start

func (mp *ManagedProcess) Start() error

Start starts the process.

Returns an error if the operation fails.

func (*ManagedProcess) StderrString

func (mp *ManagedProcess) StderrString() string

StderrString returns the captured stderr as a string.

Returns the result.

func (*ManagedProcess) StdoutString

func (mp *ManagedProcess) StdoutString() string

StdoutString returns the captured stdout as a string.

Returns the result.

func (*ManagedProcess) Stop

func (mp *ManagedProcess) Stop()

Stop stops the process, attempting graceful shutdown then force kill.

func (*ManagedProcess) WaitForText

func (mp *ManagedProcess) WaitForText(t *testing.T, text string, timeout time.Duration)

WaitForText waits for specific text to appear in the process's stdout.

t is the t. text is the text. timeout is the timeout.

type WebsocketEchoServerInfo

type WebsocketEchoServerInfo struct {
	URL         string
	CleanupFunc func()
}

WebsocketEchoServerInfo contains information about a running Websocket echo server. --- Websocket Echo Server Helper --- WebsocketEchoServerInfo contains information about a running mock WebSocket echo server.

func StartWebsocketEchoServer

func StartWebsocketEchoServer(t *testing.T) *WebsocketEchoServerInfo

StartWebsocketEchoServer starts a mock WebSocket echo server.

t is the t.

Returns the result.

Directories

Path Synopsis
cmd
command-tester command
Package main is a helper command for integration tests.
Package main is a helper command for integration tests.
mocks/grpc_authed_weather_server command
Package main implements a mock gRPC authenticated weather server for testing.
Package main implements a mock gRPC authenticated weather server for testing.
mocks/grpc_weather_server command
Package main implements a mock gRPC weather server.
Package main implements a mock gRPC weather server.
mocks/http_authed_echo_server command
Package main implements a mock HTTP authenticated echo server for testing.
Package main implements a mock HTTP authenticated echo server for testing.
mocks/http_caching_server command
Package main provides a mock HTTP caching server for integration testing.
Package main provides a mock HTTP caching server for integration testing.
mocks/http_echo_server command
Package main provides a mock HTTP echo server for integration testing.
Package main provides a mock HTTP echo server for integration testing.
mocks/openapi_weather_server command
Package main implements a mock OpenWeatherMap server.
Package main implements a mock OpenWeatherMap server.
mocks/prompt-server command
Package main implements a mock prompt server for integration tests.
Package main implements a mock prompt server for integration tests.
mocks/webrtc_weather_server command
Package main implements a mock WebRTC weather server for testing.
Package main implements a mock WebRTC weather server for testing.
mocks/websocket_echo_server command
Package main provides a mock WebSocket echo server for integration tests.
Package main provides a mock WebSocket echo server for integration tests.
Package upstream contains integration tests
Package upstream contains integration tests

Jump to

Keyboard shortcuts

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