testutil

package
v2.7.0-dev.5 Latest Latest
Warning

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

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

Documentation

Overview

Package testutil provides shared test helpers for Cogo, most notably FakeModel — a deterministic implementation of google.golang.org/adk/model.LLM that lets us drive end-to-end agent tests without burning real tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeModel

type FakeModel struct {
	ModelName string
	Script    []ScriptedResponse
	// contains filtered or unexported fields
}

FakeModel implements model.LLM with scripted output for tests.

Each call to GenerateContent advances the script by one entry. If the script is exhausted, an empty TurnComplete response is returned.

func (*FakeModel) Calls

func (f *FakeModel) Calls() int

Calls returns the number of GenerateContent invocations seen so far. Useful in tests that want to assert on call count.

func (*FakeModel) GenerateContent

func (f *FakeModel) GenerateContent(_ context.Context, _ *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error]

GenerateContent yields the next scripted response. When stream is true, each TextChunk is emitted as its own Partial event; when false, only the final consolidated event is emitted.

func (*FakeModel) Name

func (f *FakeModel) Name() string

Name reports the configured model name (or "fake" if unset).

type ScriptedResponse

type ScriptedResponse struct {
	TextChunks   []string
	InputTokens  int
	OutputTokens int
}

ScriptedResponse describes one turn of FakeModel output.

TextChunks are emitted as individual streaming Partial events (one per chunk) when the caller asks for a stream. After the chunks, FakeModel emits a single TurnComplete=true event whose Content is the concatenation of all chunks. In non-streaming mode (stream=false) only the final TurnComplete event is emitted.

InputTokens / OutputTokens populate the final event's UsageMetadata when set, so usage-tracking tests don't need a real model.

Jump to

Keyboard shortcuts

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