Documentation
¶
Overview ¶
Package e2e provides end-to-end testing utilities for ToolHive HTTP API.
Package e2e provides end-to-end testing utilities for ToolHive.
Index ¶
- func CheckTHVBinaryAvailable(config *TestConfig) error
- func CreateAndTrackGroup(config *TestConfig, groupName string, createdGroups *[]string)
- func DebugServerState(config *TestConfig, serverName string)
- func ExpectStatus(resp *http.Response, expected int)
- func GenerateUniqueServerName(prefix string) string
- func GetMCPServerURL(config *TestConfig, serverName string) (string, error)
- func GetServerLogs(config *TestConfig, serverName string) (string, error)
- func IsServerRunning(config *TestConfig, serverName string) bool
- func RemoveGroup(config *TestConfig, groupName string) error
- func StartDockerCommand(args ...string) *exec.Cmd
- func StartLongRunningTHVCommand(config *TestConfig, args ...string) *exec.Cmd
- func StopAndRemoveMCPServer(config *TestConfig, serverName string) error
- func TestMCPServerBasicFunctionality(config *TestConfig, serverURL string) error
- func WaitForMCPServer(config *TestConfig, serverName string, timeout time.Duration) error
- func WaitForMCPServerReady(config *TestConfig, serverURL string, mode string, timeout time.Duration) error
- func WaitForVMCPHealthReady(healthURL string, timeout time.Duration) error
- func WaitForWorkloadUnhealthy(config *TestConfig, serverName string, timeout time.Duration) error
- func WithAccessTokenLifespan(d time.Duration) func(*fosite.Config)
- type AuthRequest
- type MCPClientHelper
- func NewMCPClientForSSE(config *TestConfig, serverURL string) (*MCPClientHelper, error)
- func NewMCPClientForStreamableHTTP(config *TestConfig, serverURL string) (*MCPClientHelper, error)
- func NewMCPClientForStreamableHTTPWithToken(config *TestConfig, serverURL, token string) (*MCPClientHelper, error)
- func (h *MCPClientHelper) CallTool(ctx context.Context, toolName string, arguments map[string]interface{}) (*mcp.CallToolResult, error)
- func (h *MCPClientHelper) Close() error
- func (h *MCPClientHelper) ExpectResourceExists(ctx context.Context, uri string)
- func (h *MCPClientHelper) ExpectToolCall(ctx context.Context, toolName string, arguments map[string]interface{}) *mcp.CallToolResult
- func (h *MCPClientHelper) ExpectToolExists(ctx context.Context, toolName string)
- func (h *MCPClientHelper) Initialize(ctx context.Context) error
- func (h *MCPClientHelper) ListResources(ctx context.Context) (*mcp.ListResourcesResult, error)
- func (h *MCPClientHelper) ListTools(ctx context.Context) (*mcp.ListToolsResult, error)
- func (h *MCPClientHelper) Ping(ctx context.Context) error
- func (h *MCPClientHelper) ReadResource(ctx context.Context, uri string) (*mcp.ReadResourceResult, error)
- type OIDCMockServer
- func (*OIDCMockServer) CompleteAuthRequest(authReq *AuthRequest) error
- func (m *OIDCMockServer) EnableAutoComplete()
- func (m *OIDCMockServer) GetBaseURL() string
- func (m *OIDCMockServer) Start() error
- func (m *OIDCMockServer) Stop() error
- func (m *OIDCMockServer) WaitForAuthRequest(timeout time.Duration) (*AuthRequest, error)
- type OIDCMockServerOption
- type Server
- func (s *Server) BaseURL() string
- func (s *Server) Get(path string) (*http.Response, error)
- func (s *Server) GetStderr() string
- func (s *Server) GetStdout() string
- func (s *Server) GetWithHeaders(path string, headers map[string]string) (*http.Response, error)
- func (s *Server) Stop() error
- func (s *Server) WaitForReady() error
- type ServerConfig
- type THVCommand
- func (c *THVCommand) ExpectFailure() (string, string, error)
- func (c *THVCommand) ExpectSuccess() (string, string)
- func (c *THVCommand) Interrupt() error
- func (c *THVCommand) Run() (string, string, error)
- func (c *THVCommand) RunWithTimeout(timeout time.Duration) (string, string, error)
- func (c *THVCommand) WithDir(dir string) *THVCommand
- func (c *THVCommand) WithEnv(env ...string) *THVCommand
- func (c *THVCommand) WithStdin(stdin string) *THVCommand
- type TestConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckTHVBinaryAvailable ¶
func CheckTHVBinaryAvailable(config *TestConfig) error
CheckTHVBinaryAvailable checks if the thv binary is available
func CreateAndTrackGroup ¶ added in v0.2.9
func CreateAndTrackGroup(config *TestConfig, groupName string, createdGroups *[]string)
CreateAndTrackGroup creates a group and tracks it for cleanup
func DebugServerState ¶
func DebugServerState(config *TestConfig, serverName string)
DebugServerState prints debugging information about a server
func ExpectStatus ¶ added in v0.13.0
ExpectStatus reads the response body and asserts the status code, including the response body in the failure message for debugging. The response body is consumed and closed; callers must not read it again.
func GenerateUniqueServerName ¶ added in v0.6.17
GenerateUniqueServerName creates a unique server name for tests
func GetMCPServerURL ¶
func GetMCPServerURL(config *TestConfig, serverName string) (string, error)
GetMCPServerURL gets the URL for an MCP server
func GetServerLogs ¶
func GetServerLogs(config *TestConfig, serverName string) (string, error)
GetServerLogs gets the logs for a server to help with debugging
func IsServerRunning ¶ added in v0.2.9
func IsServerRunning(config *TestConfig, serverName string) bool
IsServerRunning checks if an MCP server is running
func RemoveGroup ¶ added in v0.2.9
func RemoveGroup(config *TestConfig, groupName string) error
RemoveGroup removes a group by name
func StartDockerCommand ¶ added in v0.0.40
StartDockerCommand starts a docker command with proper environment setup and returns the command
func StartLongRunningTHVCommand ¶ added in v0.0.40
func StartLongRunningTHVCommand(config *TestConfig, args ...string) *exec.Cmd
StartLongRunningTHVCommand starts a long-running ToolHive command and returns the process
func StopAndRemoveMCPServer ¶
func StopAndRemoveMCPServer(config *TestConfig, serverName string) error
StopAndRemoveMCPServer stops and removes an MCP server This function is designed for cleanup and tolerates servers that don't exist
func TestMCPServerBasicFunctionality ¶
func TestMCPServerBasicFunctionality(config *TestConfig, serverURL string) error
TestMCPServerBasicFunctionality tests basic MCP server functionality
func WaitForMCPServer ¶
func WaitForMCPServer(config *TestConfig, serverName string, timeout time.Duration) error
WaitForMCPServer waits for an MCP server to be running
func WaitForMCPServerReady ¶
func WaitForMCPServerReady(config *TestConfig, serverURL string, mode string, timeout time.Duration) error
WaitForMCPServerReady waits for an MCP server to be ready and responsive
func WaitForVMCPHealthReady ¶ added in v0.24.1
WaitForVMCPHealthReady polls the vMCP /health endpoint until it returns 200 OK or the timeout is reached. Use this instead of WaitForMCPServerReady when incoming auth is configured (MCP Initialize would fail with 401 for unauthenticated probes).
func WaitForWorkloadUnhealthy ¶ added in v0.2.7
func WaitForWorkloadUnhealthy(config *TestConfig, serverName string, timeout time.Duration) error
WaitForWorkloadUnhealthy waits for a workload to be marked as unhealthy
Types ¶
type AuthRequest ¶ added in v0.0.40
type AuthRequest struct {
ClientID string
RedirectURI string
State string
CodeChallenge string
ResponseType string
Scope string
}
AuthRequest contains the parameters from an OAuth authorization request
type MCPClientHelper ¶
type MCPClientHelper struct {
// contains filtered or unexported fields
}
MCPClientHelper provides high-level MCP client operations for e2e tests
func NewMCPClientForSSE ¶
func NewMCPClientForSSE(config *TestConfig, serverURL string) (*MCPClientHelper, error)
NewMCPClientForSSE creates a new MCP client for SSE transport
func NewMCPClientForStreamableHTTP ¶ added in v0.0.48
func NewMCPClientForStreamableHTTP(config *TestConfig, serverURL string) (*MCPClientHelper, error)
NewMCPClientForStreamableHTTP creates a new MCP client for streamable HTTP transport
func NewMCPClientForStreamableHTTPWithToken ¶ added in v0.24.1
func NewMCPClientForStreamableHTTPWithToken(config *TestConfig, serverURL, token string) (*MCPClientHelper, error)
NewMCPClientForStreamableHTTPWithToken creates a new MCP client for streamable HTTP transport that sends an Authorization Bearer token on every request. Use this when the vMCP server has OIDC incoming auth enabled.
func (*MCPClientHelper) CallTool ¶
func (h *MCPClientHelper) CallTool( ctx context.Context, toolName string, arguments map[string]interface{}, ) (*mcp.CallToolResult, error)
CallTool calls a specific tool with the given arguments
func (*MCPClientHelper) Close ¶
func (h *MCPClientHelper) Close() error
Close closes the MCP client connection
func (*MCPClientHelper) ExpectResourceExists ¶
func (h *MCPClientHelper) ExpectResourceExists(ctx context.Context, uri string)
ExpectResourceExists verifies that a resource with the given URI exists
func (*MCPClientHelper) ExpectToolCall ¶
func (h *MCPClientHelper) ExpectToolCall( ctx context.Context, toolName string, arguments map[string]interface{}, ) *mcp.CallToolResult
ExpectToolCall verifies that a tool can be called successfully
func (*MCPClientHelper) ExpectToolExists ¶
func (h *MCPClientHelper) ExpectToolExists(ctx context.Context, toolName string)
ExpectToolExists verifies that a tool with the given name exists
func (*MCPClientHelper) Initialize ¶
func (h *MCPClientHelper) Initialize(ctx context.Context) error
Initialize initializes the MCP connection
func (*MCPClientHelper) ListResources ¶
func (h *MCPClientHelper) ListResources(ctx context.Context) (*mcp.ListResourcesResult, error)
ListResources lists all available resources from the MCP server
func (*MCPClientHelper) ListTools ¶
func (h *MCPClientHelper) ListTools(ctx context.Context) (*mcp.ListToolsResult, error)
ListTools lists all available tools from the MCP server
func (*MCPClientHelper) Ping ¶
func (h *MCPClientHelper) Ping(ctx context.Context) error
Ping sends a ping to test connectivity
func (*MCPClientHelper) ReadResource ¶
func (h *MCPClientHelper) ReadResource(ctx context.Context, uri string) (*mcp.ReadResourceResult, error)
ReadResource reads a specific resource
type OIDCMockServer ¶ added in v0.0.40
type OIDCMockServer struct {
// contains filtered or unexported fields
}
OIDCMockServer represents a lightweight OIDC server using Ory Fosite
func NewOIDCMockServer ¶ added in v0.0.40
func NewOIDCMockServer(port int, clientID, clientSecret string, opts ...func(*fosite.Config)) (*OIDCMockServer, error)
NewOIDCMockServer creates a new OIDC mock server using Ory Fosite
func NewOIDCMockServerWithClientOptions ¶ added in v0.24.1
func NewOIDCMockServerWithClientOptions( port int, clientID, clientSecret string, clientOpts ...OIDCMockServerOption, ) (*OIDCMockServer, error)
NewOIDCMockServerWithClientOptions creates a new OIDC mock server, applying clientOpts to the registered test client. Use this when you need to control client-level settings such as Audience.
func (*OIDCMockServer) CompleteAuthRequest ¶ added in v0.0.40
func (*OIDCMockServer) CompleteAuthRequest(authReq *AuthRequest) error
CompleteAuthRequest automatically completes an OAuth request by making a callback
func (*OIDCMockServer) EnableAutoComplete ¶ added in v0.0.40
func (m *OIDCMockServer) EnableAutoComplete()
EnableAutoComplete enables automatic OAuth flow completion for testing
func (*OIDCMockServer) GetBaseURL ¶ added in v0.0.40
func (m *OIDCMockServer) GetBaseURL() string
GetBaseURL returns the base URL of the mock server
func (*OIDCMockServer) Start ¶ added in v0.0.40
func (m *OIDCMockServer) Start() error
Start starts the OIDC mock server
func (*OIDCMockServer) Stop ¶ added in v0.0.40
func (m *OIDCMockServer) Stop() error
Stop stops the OIDC mock server
func (*OIDCMockServer) WaitForAuthRequest ¶ added in v0.0.40
func (m *OIDCMockServer) WaitForAuthRequest(timeout time.Duration) (*AuthRequest, error)
WaitForAuthRequest waits for an OAuth authorization request and returns its parameters
type OIDCMockServerOption ¶ added in v0.24.1
type OIDCMockServerOption func(*fosite.DefaultClient)
OIDCMockServerOption configures the OIDCMockServer client registration.
func WithClientAudience ¶ added in v0.24.1
func WithClientAudience(audiences ...string) OIDCMockServerOption
WithClientAudience sets the allowed audience(s) on the registered test client. Use this when the vMCP OIDC config requires a specific audience claim in tokens.
type Server ¶ added in v0.8.0
type Server struct {
// contains filtered or unexported fields
}
Server represents a running API server instance for testing. It runs `thv serve` as a subprocess.
func NewServer ¶ added in v0.8.0
func NewServer(config *ServerConfig) (*Server, error)
NewServer creates and starts a new API server instance by running `thv serve` as a subprocess.
func StartServer ¶ added in v0.8.0
func StartServer(config *ServerConfig) *Server
StartServer is a helper function that creates and starts an API server and registers cleanup in the Ginkgo AfterEach
func (*Server) GetStderr ¶ added in v0.8.1
GetStderr returns the accumulated stderr output from the server process.
func (*Server) GetStdout ¶ added in v0.8.1
GetStdout returns the accumulated stdout output from the server process.
func (*Server) GetWithHeaders ¶ added in v0.8.0
GetWithHeaders performs a GET request with custom headers.
func (*Server) WaitForReady ¶ added in v0.8.0
WaitForReady waits for the API server to be ready to accept requests.
type ServerConfig ¶ added in v0.8.0
type ServerConfig struct {
Address string
StartTimeout time.Duration
RequestTimeout time.Duration
DebugMode bool
}
ServerConfig holds configuration for the API server in tests
func NewServerConfig ¶ added in v0.8.0
func NewServerConfig() *ServerConfig
NewServerConfig creates a new API server configuration with defaults
type THVCommand ¶
type THVCommand struct {
// contains filtered or unexported fields
}
THVCommand represents a ToolHive CLI command execution
func NewTHVCommand ¶
func NewTHVCommand(config *TestConfig, args ...string) *THVCommand
NewTHVCommand creates a new ToolHive command
func (*THVCommand) ExpectFailure ¶
func (c *THVCommand) ExpectFailure() (string, string, error)
ExpectFailure runs the command and expects it to fail
func (*THVCommand) ExpectSuccess ¶
func (c *THVCommand) ExpectSuccess() (string, string)
ExpectSuccess runs the command and expects it to succeed
func (*THVCommand) Interrupt ¶ added in v0.6.12
func (c *THVCommand) Interrupt() error
Interrupt interrupts the command and does NOT wait for it to exit.
func (*THVCommand) Run ¶
func (c *THVCommand) Run() (string, string, error)
Run executes the ToolHive command and returns stdout, stderr, and error
func (*THVCommand) RunWithTimeout ¶
RunWithTimeout executes the ToolHive command with a specific timeout
func (*THVCommand) WithDir ¶
func (c *THVCommand) WithDir(dir string) *THVCommand
WithDir sets the working directory for the command
func (*THVCommand) WithEnv ¶
func (c *THVCommand) WithEnv(env ...string) *THVCommand
WithEnv adds environment variables to the command
func (*THVCommand) WithStdin ¶ added in v0.2.9
func (c *THVCommand) WithStdin(stdin string) *THVCommand
WithStdin sets the stdin input for the command
type TestConfig ¶
TestConfig holds configuration for e2e tests
func NewTestConfig ¶
func NewTestConfig() *TestConfig
NewTestConfig creates a new test configuration with defaults
Directories
¶
| Path | Synopsis |
|---|---|
|
Package images provides centralized container image references for e2e tests.
|
Package images provides centralized container image references for e2e tests. |
|
thv-operator
|
|
|
testutil
Package testutil provides shared helpers for operator E2E tests.
|
Package testutil provides shared helpers for operator E2E tests. |
|
virtualmcp
Package virtualmcp provides helper functions for VirtualMCP E2E tests.
|
Package virtualmcp provides helper functions for VirtualMCP E2E tests. |