testutil

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package testutil provides common test utilities.

Package testutil provides common test utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupTestHome

func SetupTestHome(t *testing.T) string

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.

func StripANSI

func StripANSI(s string) string

StripANSI removes ANSI escape codes from a string. Useful for testing TUI output where lipgloss adds styling.

func WriteTestConfig

func WriteTestConfig(t *testing.T, configJSON string) string

WriteTestConfig writes a test configuration file to the isolated $HOME.

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) Clear

func (c *EventCollector) Clear()

Clear resets the collector's state.

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.

Jump to

Keyboard shortcuts

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