ExMcp.Test.Support.Transports (ex_mcp v0.9.2)

View Source

Test support module for transport-related testing utilities.

This module provides helpers for testing different transport mechanisms used in ExMCP, including HTTP, stdio, and BEAM transports. It includes mock transport implementations and utilities for testing transport behavior.

Summary

Functions

Creates a transport message in the expected format.

Simulates a transport connection for testing.

Creates transport headers for HTTP testing.

Creates a mock transport configuration for testing.

Simulates transport errors for testing error handling.

Creates a mock transport process for testing.

Validates transport configuration for testing.

Functions

format_transport_message(method, params)

@spec format_transport_message(String.t(), map()) :: map()

Creates a transport message in the expected format.

Formats messages according to the transport protocol specifications for use in testing scenarios.

mock_connection(transport_type, opts \\ [])

@spec mock_connection(
  atom(),
  keyword()
) :: %{transport: atom(), config: map(), pid: pid() | nil}

Simulates a transport connection for testing.

This function creates a mock connection that can be used in tests to verify transport behavior without external dependencies.

mock_http_headers(opts \\ [])

@spec mock_http_headers(keyword()) :: map()

Creates transport headers for HTTP testing.

Generates appropriate headers for different HTTP test scenarios, including authentication headers and content type headers.

mock_transport_config(transport_type, opts \\ [])

@spec mock_transport_config(
  atom(),
  keyword()
) :: map()

Creates a mock transport configuration for testing.

Parameters

  • transport_type - The type of transport (:http, :stdio, :beam, :test)
  • opts - Additional options for the transport

Returns

A transport configuration map suitable for testing.

simulate_transport_error(error_type)

@spec simulate_transport_error(atom()) :: {:error, term()}

Simulates transport errors for testing error handling.

Creates various error scenarios that can occur during transport operations to test error handling and recovery mechanisms.

start_mock_transport(transport_type, opts \\ [])

@spec start_mock_transport(
  atom(),
  keyword()
) :: {:ok, pid()} | {:error, term()}

Creates a mock transport process for testing.

This creates a GenServer process that simulates transport behavior for testing purposes without requiring actual network connections.

validate_transport_config(config)

@spec validate_transport_config(map()) :: :ok | {:error, String.t()}

Validates transport configuration for testing.

Ensures that transport configurations are valid and contain required fields for testing scenarios.