mock

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package mock provides a deterministic mock source for testing agentwatch monitors. It implements source.Source with scripted results, error injection, and call recording.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiscoverCall

type DiscoverCall struct{}

DiscoverCall records a single invocation of Discover.

type Option

type Option func(*Source)

Option configures a Source.

func WithDefaultParse

func WithDefaultParse(update source.SourceUpdate, cursor source.Cursor, err error) Option

WithDefaultParse sets a fallback Parse result used for any session whose scripted queue is empty. The default is not consumed — it repeats on every call.

func WithDiscoverError

func WithDiscoverError(err error) Option

WithDiscoverError queues a Discover result that returns err.

func WithHandles

func WithHandles(handles ...source.SessionHandle) Option

WithHandles queues a Discover result that returns the given handles (no error). Multiple calls append results in order.

func WithName

func WithName(name string) Option

WithName sets the source name returned by Name.

func WithParseResult

func WithParseResult(sessionID string, update source.SourceUpdate, cursor source.Cursor, err error) Option

WithParseResult queues a Parse result for the given sessionID. Multiple calls for the same sessionID append results in order.

type ParseCall

type ParseCall struct {
	Handle source.SessionHandle
	Cursor source.Cursor
}

ParseCall records a single invocation of Parse, including the arguments.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source is a deterministic mock that implements source.Source. Construct it with New and configure it with Option functions or the Queue* methods for runtime mutations.

func New

func New(opts ...Option) *Source

New creates a new mock Source with the given options.

func (*Source) AddUpdate

func (s *Source) AddUpdate(sessionID string, update source.SourceUpdate, cursor source.Cursor)

AddUpdate queues a Parse result for the given sessionID with no error. Convenience method for tests.

func (*Source) Discover

func (s *Source) Discover(ctx context.Context) ([]source.SessionHandle, error)

Discover implements source.Source. It dequeues and returns the next scripted result. When the queue is exhausted it returns permanentHandles (set via SetHandles), or nil if none are configured.

func (*Source) DiscoverCallCount

func (s *Source) DiscoverCallCount() int

DiscoverCallCount returns the number of times Discover has been called.

func (*Source) Name

func (s *Source) Name() string

Name implements source.Source.

func (*Source) Parse

Parse implements source.Source. It dequeues the next scripted result for h.ID. If none remains it falls back to the default result, or returns a zero SourceUpdate with the incoming cursor unchanged.

func (*Source) ParseCallCount

func (s *Source) ParseCallCount() int

ParseCallCount returns the number of times Parse has been called.

func (*Source) ParseCalls

func (s *Source) ParseCalls() []ParseCall

ParseCalls returns a snapshot of all recorded Parse invocations.

func (*Source) QueueDiscoverError

func (s *Source) QueueDiscoverError(err error)

QueueDiscoverError enqueues a Discover result that returns err. Safe to call after construction (runtime mutation).

func (*Source) QueueHandles

func (s *Source) QueueHandles(handles ...source.SessionHandle)

QueueHandles enqueues a Discover result returning the given handles. Safe to call after construction (runtime mutation).

func (*Source) QueueParseResult

func (s *Source) QueueParseResult(sessionID string, update source.SourceUpdate, cursor source.Cursor, err error)

QueueParseResult enqueues a Parse result for sessionID. Safe to call after construction (runtime mutation).

func (*Source) SetHandles

func (s *Source) SetHandles(handles []source.SessionHandle)

SetHandles sets permanent handles returned by Discover when the queue is empty. Unlike WithHandles (which queues a one-shot result), SetHandles persists across all subsequent Discover calls. Convenience method for tests.

Jump to

Keyboard shortcuts

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