Documentation
¶
Index ¶
- Variables
- func AssertOutputContains(t *testing.T, tm *teatest.TestModel, expected string)
- func CleanupTeatestTmuxServer(t *testing.T)
- func CleanupTmuxSessionsWithPrefix(t *testing.T, prefix string)
- func CreateMinimalApp(t *testing.T) tea.Model
- func CreateTUITest(t *testing.T, model tea.Model, config TUITestConfig) *teatest.TestModel
- func NonEmptyContent(content string) bool
- func ReadOutput(t *testing.T, r io.Reader) string
- func RetryOperation(operation func() error, config WaitConfig) error
- func TempSessionName(prefix string, id int) string
- func WaitForCondition(condition func() bool, config WaitConfig) error
- func WaitForConditionWithError(condition func() (bool, error), config WaitConfig) error
- func WaitForContent(getter func() (string, error), validator ContentValidator, config WaitConfig) (string, error)
- func WaitForOutputContains(t *testing.T, tm *teatest.TestModel, expected string, timeout time.Duration)
- func WaitForOutputContainsAfterAction(t *testing.T, tm *teatest.TestModel, expected string, ...)
- func WaitForSession(instance *session.Instance) error
- func WaitForSessionPreview(instance *session.Instance, validator ContentValidator) (string, error)
- func WaitForSessionPreviewContaining(instance *session.Instance, text string) (string, error)
- func WaitForSessionWithTimeout(instance *session.Instance, config WaitConfig) error
- func WaitForTmuxContent(session *tmux.TmuxSession, validator ContentValidator) (string, error)
- func WaitForTmuxContentContaining(session *tmux.TmuxSession, text string) (string, error)
- func WaitForTmuxSession(session *tmux.TmuxSession) error
- func WaitForTmuxSessionWithTimeout(session *tmux.TmuxSession, config WaitConfig) error
- type CommandExecutor
- type ContentValidator
- type ExpectSessionConfig
- type MockCommandExecutor
- type RealCommandExecutor
- type SessionWaiter
- func (w *SessionWaiter) WaitForFullyReady() error
- func (w *SessionWaiter) WaitForFullyReadyWithTimeout(config WaitConfig) error
- func (w *SessionWaiter) WaitForNonEmptyPreview() (string, error)
- func (w *SessionWaiter) WaitForPreview(validator ContentValidator) (string, error)
- func (w *SessionWaiter) WaitForPreviewContaining(text string) (string, error)
- func (w *SessionWaiter) WaitForPreviewWithConfig(validator ContentValidator, config WaitConfig) (string, error)
- func (w *SessionWaiter) WaitForStarted() error
- func (w *SessionWaiter) WaitForTmuxAlive() error
- type TUISession
- func (s *TUISession) Close() error
- func (s *TUISession) ExpectOneOf(strings []string, timeout time.Duration) (string, error)
- func (s *TUISession) ExpectPattern(pattern string, timeout time.Duration) (string, error)
- func (s *TUISession) ExpectString(str string, timeout time.Duration) error
- func (s *TUISession) GetOutput() (string, error)
- func (s *TUISession) IsRunning() bool
- func (s *TUISession) SendArrowDown() error
- func (s *TUISession) SendArrowLeft() error
- func (s *TUISession) SendArrowRight() error
- func (s *TUISession) SendArrowUp() error
- func (s *TUISession) SendCtrlC() error
- func (s *TUISession) SendCtrlD() error
- func (s *TUISession) SendEnter() error
- func (s *TUISession) SendEscape() error
- func (s *TUISession) SendKeys(keys string) error
- func (s *TUISession) SendLine(text string) error
- func (s *TUISession) SendTab() error
- func (s *TUISession) Snapshot() (string, error)
- func (s *TUISession) WaitForCondition(condition func() bool, timeout time.Duration, pollInterval time.Duration) error
- func (s *TUISession) WaitForExit(timeout time.Duration) error
- func (s *TUISession) WaitForPrompt(timeout time.Duration) error
- type TUITestConfig
- type TmuxTestServer
- func (s *TmuxTestServer) Cleanup()
- func (s *TmuxTestServer) CreateSession(sessionName string, command string) (*tmux.TmuxSession, error)
- func (s *TmuxTestServer) CreateSessionWithoutStarting(sessionName string, command string, prefix string) *tmux.TmuxSession
- func (s *TmuxTestServer) GetSocketName() string
- func (s *TmuxTestServer) KillAllSessions() error
- func (s *TmuxTestServer) KillServer() error
- func (s *TmuxTestServer) KillSession(sessionName string) error
- func (s *TmuxTestServer) ListSessions() ([]string, error)
- func (s *TmuxTestServer) SessionExists(sessionName string) bool
- type TmuxWaiter
- func (w *TmuxWaiter) WaitForContent(validator ContentValidator) (string, error)
- func (w *TmuxWaiter) WaitForContentContaining(text string) (string, error)
- func (w *TmuxWaiter) WaitForContentWithConfig(validator ContentValidator, config WaitConfig) (string, error)
- func (w *TmuxWaiter) WaitForNonEmptyContent() (string, error)
- func (w *TmuxWaiter) WaitForSessionExists() error
- func (w *TmuxWaiter) WaitForSessionExistsWithConfig(config WaitConfig) error
- func (w *TmuxWaiter) WaitForSessionReady() error
- func (w *TmuxWaiter) WaitForSessionReadyWithTimeout(config WaitConfig) error
- type WaitConfig
Constants ¶
This section is empty.
Variables ¶
var ( FastTimeout = 2 * time.Second // For unit tests and quick operations DefaultTimeout = 10 * time.Second // For most integration tests SlowTimeout = 30 * time.Second // For complex operations (file I/O, network) )
Common timeout durations for different test scenarios
Functions ¶
func AssertOutputContains ¶
AssertOutputContains checks if current output contains the expected text
func CleanupTeatestTmuxServer ¶
CleanupTeatestTmuxServer cleans up the isolated tmux server for a specific test
func CleanupTmuxSessionsWithPrefix ¶
CleanupTmuxSessionsWithPrefix cleans up tmux sessions with a specific prefix. This is useful for cleaning up sessions created by legacy tests that don't use isolated servers.
func CreateMinimalApp ¶
CreateMinimalApp creates a minimal app model for testing basic functionality
func CreateTUITest ¶
CreateTUITest creates a new teatest instance with the given model
func NonEmptyContent ¶
NonEmptyContent validates that content is not empty
func ReadOutput ¶
ReadOutput reads all content from an io.Reader and returns it as a string
func RetryOperation ¶
func RetryOperation(operation func() error, config WaitConfig) error
RetryOperation retries an operation with exponential backoff
func TempSessionName ¶
TempSessionName generates a temporary session name with an ID
func WaitForCondition ¶
func WaitForCondition(condition func() bool, config WaitConfig) error
WaitForCondition polls a condition until it returns true or timeout occurs
func WaitForConditionWithError ¶
func WaitForConditionWithError(condition func() (bool, error), config WaitConfig) error
WaitForConditionWithError polls a condition that can return an error
func WaitForContent ¶
func WaitForContent(getter func() (string, error), validator ContentValidator, config WaitConfig) (string, error)
WaitForContent polls a content getter until the validator returns true
func WaitForOutputContains ¶
func WaitForOutputContains(t *testing.T, tm *teatest.TestModel, expected string, timeout time.Duration)
WaitForOutputContains waits until the output contains the expected text using teatest.WaitFor
func WaitForOutputContainsAfterAction ¶
func WaitForOutputContainsAfterAction(t *testing.T, tm *teatest.TestModel, expected string, actionDelay time.Duration)
WaitForOutputContainsAfterAction waits for an action to complete, then checks if output contains expected text This version avoids output stream consumption issues by using a single read approach
func WaitForSession ¶
WaitForSession waits for a session to be fully ready
func WaitForSessionPreview ¶
func WaitForSessionPreview(instance *session.Instance, validator ContentValidator) (string, error)
WaitForSessionPreview waits for session to have specific preview content
func WaitForSessionPreviewContaining ¶
WaitForSessionPreviewContaining waits for session preview containing text
func WaitForSessionWithTimeout ¶
func WaitForSessionWithTimeout(instance *session.Instance, config WaitConfig) error
WaitForSessionWithTimeout waits for session with custom timeout
func WaitForTmuxContent ¶
func WaitForTmuxContent(session *tmux.TmuxSession, validator ContentValidator) (string, error)
WaitForTmuxContent waits for tmux session to have specific content
func WaitForTmuxContentContaining ¶
func WaitForTmuxContentContaining(session *tmux.TmuxSession, text string) (string, error)
WaitForTmuxContentContaining waits for tmux content containing text
func WaitForTmuxSession ¶
func WaitForTmuxSession(session *tmux.TmuxSession) error
WaitForTmuxSession waits for a tmux session to be ready
func WaitForTmuxSessionWithTimeout ¶
func WaitForTmuxSessionWithTimeout(session *tmux.TmuxSession, config WaitConfig) error
WaitForTmuxSessionWithTimeout waits for tmux session with custom timeout
Types ¶
type CommandExecutor ¶
type CommandExecutor interface {
// Command creates a new *exec.Cmd with the given name and arguments
Command(name string, args ...string) *exec.Cmd
// Output runs the command and returns its standard output
Output(cmd *exec.Cmd) ([]byte, error)
// LookPath searches for an executable named file in the directories listed in the PATH environment variable
LookPath(file string) (string, error)
}
CommandExecutor defines the interface for executing external commands This allows for dependency injection and mocking in tests
type ContentValidator ¶
ContentValidator is a function that validates content
func ContainsText ¶
func ContainsText(text string) ContentValidator
ContainsText validates that content contains specific text
type ExpectSessionConfig ¶
type ExpectSessionConfig struct {
// Command to run (defaults to "./stapler-squad")
Command string
// Arguments to pass to command
Args []string
// Environment variables
Env []string
// Working directory
WorkDir string
// Timeout for operations (default 30s)
Timeout time.Duration
// Width and height of terminal
Cols, Rows uint16
}
ExpectSessionConfig configures expect-based TUI session behavior
func DefaultExpectConfig ¶
func DefaultExpectConfig() ExpectSessionConfig
DefaultExpectConfig returns default expect testing configuration
type MockCommandExecutor ¶
type MockCommandExecutor struct {
// CommandFunc is called when Command is invoked
CommandFunc func(name string, args ...string) *exec.Cmd
// OutputFunc is called when Output is invoked
OutputFunc func(cmd *exec.Cmd) ([]byte, error)
// LookPathFunc is called when LookPath is invoked
LookPathFunc func(file string) (string, error)
}
MockCommandExecutor implements CommandExecutor for testing
func NewMockCommandExecutor ¶
func NewMockCommandExecutor() *MockCommandExecutor
NewMockCommandExecutor creates a new MockCommandExecutor with default behavior
func NewMockCommandExecutorWithClaudeFound ¶
func NewMockCommandExecutorWithClaudeFound(claudePath string) *MockCommandExecutor
NewMockCommandExecutorWithClaudeFound creates a mock that simulates finding claude
func NewMockCommandExecutorWithClaudeNotFound ¶
func NewMockCommandExecutorWithClaudeNotFound() *MockCommandExecutor
NewMockCommandExecutorWithClaudeNotFound creates a mock that simulates claude not being found
func (*MockCommandExecutor) Command ¶
func (m *MockCommandExecutor) Command(name string, args ...string) *exec.Cmd
type RealCommandExecutor ¶
type RealCommandExecutor struct{}
RealCommandExecutor implements CommandExecutor using actual system commands
func (*RealCommandExecutor) Command ¶
func (r *RealCommandExecutor) Command(name string, args ...string) *exec.Cmd
type SessionWaiter ¶
type SessionWaiter struct {
// contains filtered or unexported fields
}
SessionWaiter provides utilities for waiting on session operations
func NewSessionWaiter ¶
func NewSessionWaiter(instance *session.Instance) *SessionWaiter
NewSessionWaiter creates a new session waiter
func (*SessionWaiter) WaitForFullyReady ¶
func (w *SessionWaiter) WaitForFullyReady() error
WaitForFullyReady waits for session to be started, tmux alive, and have content
func (*SessionWaiter) WaitForFullyReadyWithTimeout ¶
func (w *SessionWaiter) WaitForFullyReadyWithTimeout(config WaitConfig) error
WaitForFullyReadyWithTimeout waits for session with custom timeout
func (*SessionWaiter) WaitForNonEmptyPreview ¶
func (w *SessionWaiter) WaitForNonEmptyPreview() (string, error)
WaitForNonEmptyPreview waits for any non-empty preview content
func (*SessionWaiter) WaitForPreview ¶
func (w *SessionWaiter) WaitForPreview(validator ContentValidator) (string, error)
WaitForPreview waits for the session to have preview content
func (*SessionWaiter) WaitForPreviewContaining ¶
func (w *SessionWaiter) WaitForPreviewContaining(text string) (string, error)
WaitForPreviewContaining waits for preview containing specific text
func (*SessionWaiter) WaitForPreviewWithConfig ¶
func (w *SessionWaiter) WaitForPreviewWithConfig(validator ContentValidator, config WaitConfig) (string, error)
WaitForPreviewWithConfig waits for preview with custom config
func (*SessionWaiter) WaitForStarted ¶
func (w *SessionWaiter) WaitForStarted() error
WaitForStarted waits for the session to be started
func (*SessionWaiter) WaitForTmuxAlive ¶
func (w *SessionWaiter) WaitForTmuxAlive() error
WaitForTmuxAlive waits for the tmux session to be alive
type TUISession ¶
type TUISession struct {
// contains filtered or unexported fields
}
TUISession represents an interactive TUI testing session
func StartExpectSession ¶
func StartExpectSession(t *testing.T, config ExpectSessionConfig) (*TUISession, error)
StartExpectSession starts a new interactive TUI session for testing with expect
func (*TUISession) ExpectOneOf ¶
ExpectOneOf waits for any of the provided strings to appear
func (*TUISession) ExpectPattern ¶
ExpectPattern waits for output matching a regex pattern
func (*TUISession) ExpectString ¶
func (s *TUISession) ExpectString(str string, timeout time.Duration) error
ExpectString waits for a specific string to appear in the output
func (*TUISession) GetOutput ¶
func (s *TUISession) GetOutput() (string, error)
GetOutput gets all available output without blocking
func (*TUISession) IsRunning ¶
func (s *TUISession) IsRunning() bool
IsRunning checks if the TUI process is still running
func (*TUISession) SendArrowDown ¶
func (s *TUISession) SendArrowDown() error
SendArrowDown sends down arrow key
func (*TUISession) SendArrowLeft ¶
func (s *TUISession) SendArrowLeft() error
SendArrowLeft sends left arrow key
func (*TUISession) SendArrowRight ¶
func (s *TUISession) SendArrowRight() error
SendArrowRight sends right arrow key
func (*TUISession) SendArrowUp ¶
func (s *TUISession) SendArrowUp() error
SendArrowUp sends up arrow key
func (*TUISession) SendEnter ¶
func (s *TUISession) SendEnter() error
SendEnter sends Enter/Return key
func (*TUISession) SendKeys ¶
func (s *TUISession) SendKeys(keys string) error
SendKeys sends a sequence of keys to the TUI
func (*TUISession) SendLine ¶
func (s *TUISession) SendLine(text string) error
SendLine sends a line of text followed by Enter
func (*TUISession) Snapshot ¶
func (s *TUISession) Snapshot() (string, error)
Snapshot captures current screen content
func (*TUISession) WaitForCondition ¶
func (s *TUISession) WaitForCondition(condition func() bool, timeout time.Duration, pollInterval time.Duration) error
WaitForCondition waits for a custom condition with polling
func (*TUISession) WaitForExit ¶
func (s *TUISession) WaitForExit(timeout time.Duration) error
WaitForExit waits for the TUI to exit
func (*TUISession) WaitForPrompt ¶
func (s *TUISession) WaitForPrompt(timeout time.Duration) error
WaitForPrompt waits for a common prompt pattern
type TUITestConfig ¶
TUITestConfig contains configuration for TUI tests
func DefaultTUIConfig ¶
func DefaultTUIConfig() TUITestConfig
DefaultTUIConfig returns sensible defaults for TUI testing
type TmuxTestServer ¶
type TmuxTestServer struct {
// contains filtered or unexported fields
}
TmuxTestServer represents an isolated tmux server for testing. Each test gets its own tmux server socket to prevent interference between tests.
func CreateIsolatedTmuxServer ¶
func CreateIsolatedTmuxServer(t *testing.T) *TmuxTestServer
CreateIsolatedTmuxServer creates a new isolated tmux server for testing. The server uses a unique socket name based on the test name to prevent conflicts. Cleanup is automatically registered with t.Cleanup().
func (*TmuxTestServer) Cleanup ¶
func (s *TmuxTestServer) Cleanup()
Cleanup performs cleanup of the isolated tmux server. This is automatically called via t.Cleanup() but can also be called manually.
func (*TmuxTestServer) CreateSession ¶
func (s *TmuxTestServer) CreateSession(sessionName string, command string) (*tmux.TmuxSession, error)
CreateSession creates and starts a new tmux session on this isolated server
func (*TmuxTestServer) CreateSessionWithoutStarting ¶
func (s *TmuxTestServer) CreateSessionWithoutStarting(sessionName string, command string, prefix string) *tmux.TmuxSession
CreateSessionWithoutStarting creates a tmux session object without starting it. This is useful for testing timeout and hang scenarios.
func (*TmuxTestServer) GetSocketName ¶
func (s *TmuxTestServer) GetSocketName() string
GetSocketName returns the socket name for this isolated server
func (*TmuxTestServer) KillAllSessions ¶
func (s *TmuxTestServer) KillAllSessions() error
KillAllSessions kills all sessions on this isolated server
func (*TmuxTestServer) KillServer ¶
func (s *TmuxTestServer) KillServer() error
KillServer kills the entire tmux server (all sessions)
func (*TmuxTestServer) KillSession ¶
func (s *TmuxTestServer) KillSession(sessionName string) error
KillSession kills a specific session on this server
func (*TmuxTestServer) ListSessions ¶
func (s *TmuxTestServer) ListSessions() ([]string, error)
ListSessions returns all session names on this isolated server
func (*TmuxTestServer) SessionExists ¶
func (s *TmuxTestServer) SessionExists(sessionName string) bool
SessionExists checks if a session exists on this server
type TmuxWaiter ¶
type TmuxWaiter struct {
// contains filtered or unexported fields
}
TmuxWaiter provides utilities for waiting on tmux operations
func NewTmuxWaiter ¶
func NewTmuxWaiter(session *tmux.TmuxSession) *TmuxWaiter
NewTmuxWaiter creates a new tmux waiter
func (*TmuxWaiter) WaitForContent ¶
func (w *TmuxWaiter) WaitForContent(validator ContentValidator) (string, error)
WaitForContent waits for tmux session to have specific content
func (*TmuxWaiter) WaitForContentContaining ¶
func (w *TmuxWaiter) WaitForContentContaining(text string) (string, error)
WaitForContentContaining waits for content containing specific text
func (*TmuxWaiter) WaitForContentWithConfig ¶
func (w *TmuxWaiter) WaitForContentWithConfig(validator ContentValidator, config WaitConfig) (string, error)
WaitForContentWithConfig waits for content with custom config
func (*TmuxWaiter) WaitForNonEmptyContent ¶
func (w *TmuxWaiter) WaitForNonEmptyContent() (string, error)
WaitForNonEmptyContent waits for any non-empty content
func (*TmuxWaiter) WaitForSessionExists ¶
func (w *TmuxWaiter) WaitForSessionExists() error
WaitForSessionExists waits for the tmux session to exist
func (*TmuxWaiter) WaitForSessionExistsWithConfig ¶
func (w *TmuxWaiter) WaitForSessionExistsWithConfig(config WaitConfig) error
WaitForSessionExistsWithConfig waits for session with custom config
func (*TmuxWaiter) WaitForSessionReady ¶
func (w *TmuxWaiter) WaitForSessionReady() error
WaitForSessionReady waits for session to exist and have content
func (*TmuxWaiter) WaitForSessionReadyWithTimeout ¶
func (w *TmuxWaiter) WaitForSessionReadyWithTimeout(config WaitConfig) error
WaitForSessionReadyWithTimeout waits for session with custom timeout
type WaitConfig ¶
type WaitConfig struct {
Timeout time.Duration
PollInterval time.Duration
Description string // For better error messages
}
WaitConfig allows customizing wait behavior
func DefaultWaitConfig ¶
func DefaultWaitConfig() WaitConfig
DefaultWaitConfig provides sensible defaults