mock

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package mock provides a configurable mock A2A server for use in tests.

It serves canned responses per skill with optional input matching, latency injection, and error injection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type A2AServer

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

A2AServer is a lightweight mock A2A server backed by httptest.Server.

func NewA2AServer

func NewA2AServer(card *a2a.AgentCard, opts ...Option) *A2AServer

NewA2AServer creates a mock server with the given card and options. Call Start to begin serving.

func (*A2AServer) Close

func (m *A2AServer) Close()

Close shuts down the server.

func (*A2AServer) Start

func (m *A2AServer) Start() (string, error)

Start starts the underlying httptest.Server and returns its URL.

func (*A2AServer) URL

func (m *A2AServer) URL() string

URL returns the URL of the running server. Panics if not started.

type AgentConfig

type AgentConfig struct {
	Name      string        `json:"name" yaml:"name"`
	Card      a2a.AgentCard `json:"card" yaml:"card"`
	Responses []RuleConfig  `json:"responses" yaml:"responses"`
}

AgentConfig is the YAML-friendly configuration for a mock agent.

type MatchConfig

type MatchConfig struct {
	Contains string `json:"contains,omitempty" yaml:"contains,omitempty"`
	Regex    string `json:"regex,omitempty" yaml:"regex,omitempty"`
}

MatchConfig describes how to match incoming messages.

type Option

type Option func(*A2AServer)

Option configures an A2AServer.

func OptionsFromConfig

func OptionsFromConfig(cfg *AgentConfig) []Option

OptionsFromConfig converts an AgentConfig's response rules into Options.

func WithInputMatcher

func WithInputMatcher(skillID string, fn func(a2a.Message) bool, response Response) Option

WithInputMatcher adds a rule that fires when the matcher returns true for the given skill ID. Rules are evaluated in order; first match wins.

func WithLatency

func WithLatency(d time.Duration) Option

WithLatency adds a delay before processing each message/send request.

func WithSkillError

func WithSkillError(skillID, errMsg string) Option

WithSkillError adds a rule that returns a failed task for the given skill ID.

func WithSkillResponse

func WithSkillResponse(skillID string, response Response) Option

WithSkillResponse adds a rule that returns response for the given skill ID.

type PartConfig

type PartConfig struct {
	Text string `json:"text" yaml:"text"`
}

PartConfig describes a single response part.

type Response

type Response struct {
	Parts []a2a.Part
}

Response holds the parts returned by a matched rule.

type ResponseConfig

type ResponseConfig struct {
	Parts []PartConfig `json:"parts" yaml:"parts"`
}

ResponseConfig describes the response parts.

type RuleConfig

type RuleConfig struct {
	Skill    string          `json:"skill" yaml:"skill"`
	Match    *MatchConfig    `json:"match,omitempty" yaml:"match,omitempty"`
	Response *ResponseConfig `json:"response,omitempty" yaml:"response,omitempty"`
	Error    string          `json:"error,omitempty" yaml:"error,omitempty"`
}

RuleConfig describes a single response rule.

Jump to

Keyboard shortcuts

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