Documentation
¶
Overview ¶
Package testutil provides common test utilities.
Package testutil provides common test utilities.
Index ¶
- func SetupTestHome(t *testing.T) string
- func StatesContainSequence(observed, expected []events.RuntimeState) bool
- func StripANSI(s string) string
- func WriteTestConfig(t *testing.T, configJSON string) string
- type EventCollector
- func (c *EventCollector) Clear()
- func (c *EventCollector) Events() []events.Event
- func (c *EventCollector) Handler(e events.Event)
- func (c *EventCollector) LastStateFor(serverID string) events.RuntimeState
- func (c *EventCollector) StatesFor(serverID string) []events.RuntimeState
- func (c *EventCollector) ToolsFor(serverID string) []events.McpTool
- func (c *EventCollector) WaitForAnyState(serverID string, states []events.RuntimeState, timeout time.Duration) (events.RuntimeState, bool)
- func (c *EventCollector) WaitForState(serverID string, state events.RuntimeState, timeout time.Duration) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetupTestHome ¶
SetupTestHome creates an isolated $HOME directory for tests. This is critical because: - PIDTracker reads/writes per-owner registries under ~/.config/mcpmu/ - Config reads/writes ~/.config/mcpmu/config.json - Orphan cleanup runs on NewSupervisor() and could kill real processes
The temp directory is automatically cleaned up when the test ends.
func StatesContainSequence ¶
func StatesContainSequence(observed, expected []events.RuntimeState) bool
StatesContainSequence checks if the observed states contain the expected sequence in order. The expected sequence doesn't need to be contiguous - there can be other states in between.
Types ¶
type EventCollector ¶
type EventCollector struct {
// contains filtered or unexported fields
}
EventCollector is a thread-safe event collector for test assertions. Subscribe it to an event bus and then query collected events.
func NewEventCollector ¶
func NewEventCollector() *EventCollector
NewEventCollector creates a new EventCollector.
func (*EventCollector) Events ¶
func (c *EventCollector) Events() []events.Event
Events returns all collected events.
func (*EventCollector) Handler ¶
func (c *EventCollector) Handler(e events.Event)
Handler returns a function suitable for bus.Subscribe().
func (*EventCollector) LastStateFor ¶
func (c *EventCollector) LastStateFor(serverID string) events.RuntimeState
LastStateFor returns the most recent state for a server ID. Returns StateIdle if no states have been observed.
func (*EventCollector) StatesFor ¶
func (c *EventCollector) StatesFor(serverID string) []events.RuntimeState
StatesFor returns all states observed for a server ID.
func (*EventCollector) ToolsFor ¶
func (c *EventCollector) ToolsFor(serverID string) []events.McpTool
ToolsFor returns the most recent tools for a server ID. Returns nil if no tools have been observed.
func (*EventCollector) WaitForAnyState ¶
func (c *EventCollector) WaitForAnyState(serverID string, states []events.RuntimeState, timeout time.Duration) (events.RuntimeState, bool)
WaitForAnyState blocks until any of the specified states is observed or timeout expires. Returns the observed state and true, or StateIdle and false on timeout.
func (*EventCollector) WaitForState ¶
func (c *EventCollector) WaitForState(serverID string, state events.RuntimeState, timeout time.Duration) bool
WaitForState blocks until the specified state is observed or timeout expires. Returns true if the state was observed, false on timeout.