testutil

package
v0.13.31 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testutil provides utilities for integration testing agnt components.

It includes helpers for: - Setting up test web servers - Creating mock agents for PTY testing - Managing test daemon instances - Common test fixtures and assertions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFreePort

func GetFreePort(t *testing.T) int

GetFreePort returns an available TCP port.

func RequireChrome

func RequireChrome(t *testing.T) string

RequireChrome skips the test if Chrome is not available.

func TempDir

func TempDir(t *testing.T) string

TempDir creates a temporary directory for the test.

func TempFile

func TempFile(t *testing.T, content string) string

TempFile creates a temporary file with the given content.

func WaitForPort

func WaitForPort(t *testing.T, port int, timeout time.Duration) bool

WaitForPort waits for a TCP port to become available.

Types

type MockAgent

type MockAgent struct {
	Cmd    *exec.Cmd
	Stdin  io.WriteCloser
	Stdout io.ReadCloser
	Stderr io.ReadCloser
	// contains filtered or unexported fields
}

MockAgent represents a mock AI agent process for PTY testing.

func StartMockAgent

func StartMockAgent(t *testing.T, opts ...MockAgentOption) *MockAgent

StartMockAgent starts the mock agent process.

func (*MockAgent) ClearOutput

func (a *MockAgent) ClearOutput()

ClearOutput clears the output buffer.

func (*MockAgent) GetOutput

func (a *MockAgent) GetOutput() string

GetOutput returns all collected output.

func (*MockAgent) SendInput

func (a *MockAgent) SendInput(input string) error

SendInput sends input to the mock agent.

func (*MockAgent) Stop

func (a *MockAgent) Stop()

Stop stops the mock agent.

func (*MockAgent) WaitForOutput

func (a *MockAgent) WaitForOutput(substr string, timeout time.Duration) bool

WaitForOutput waits for output containing the given substring.

type MockAgentOption

type MockAgentOption func(*mockAgentConfig)

MockAgentOption configures the mock agent.

func WithDelay

func WithDelay(ms int) MockAgentOption

WithDelay sets the response delay in milliseconds.

func WithEchoMode

func WithEchoMode() MockAgentOption

WithEchoMode enables echo mode.

func WithOutputLines

func WithOutputLines(n int) MockAgentOption

WithOutputLines sets the number of output lines per response.

type RequestLog

type RequestLog struct {
	Time    time.Time
	Method  string
	Path    string
	Headers http.Header
}

RequestLog stores information about a request.

type TestWebApp

type TestWebApp struct {
	Server   *httptest.Server
	URL      string
	Requests []RequestLog
	// contains filtered or unexported fields
}

TestWebApp represents a test web application server.

func NewTestWebApp

func NewTestWebApp(t *testing.T) *TestWebApp

NewTestWebApp creates a test web server that serves the static test pages.

func (*TestWebApp) ClearRequests

func (app *TestWebApp) ClearRequests()

ClearRequests clears the request log.

func (*TestWebApp) GetRequestCount

func (app *TestWebApp) GetRequestCount() int

GetRequestCount returns the number of requests received.

func (*TestWebApp) GetRequests

func (app *TestWebApp) GetRequests() []RequestLog

GetRequests returns a copy of all logged requests.

Jump to

Keyboard shortcuts

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