testutil

package
v0.0.0-...-6aca404 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

============================================================================= 🧪 测试辅助函数 ============================================================================= 提供通用的测试辅助函数和断言

使用方法:

testutil.AssertMessagesEqual(t, expected, actual)
testutil.AssertEventuallyTrue(t, func() bool { return condition }, 5*time.Second)

=============================================================================

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContains

func AssertContains(t *testing.T, s, substr string)

AssertContains 断言字符串包含子串

func AssertError

func AssertError(t *testing.T, err error, msgAndArgs ...any)

AssertError 断言有错误

func AssertEventuallyEqual

func AssertEventuallyEqual(t *testing.T, expected any, getter func() any, timeout time.Duration)

AssertEventuallyEqual 断言值最终相等

func AssertEventuallyTrue

func AssertEventuallyTrue(t *testing.T, condition func() bool, timeout time.Duration)

AssertEventuallyTrue 断言条件最终为真

func AssertJSONEqual

func AssertJSONEqual(t *testing.T, expected, actual any)

AssertJSONEqual 断言两个值的 JSON 表示相等

func AssertMessagesEqual

func AssertMessagesEqual(t *testing.T, expected, actual []types.Message)

AssertMessagesEqual 断言两个消息切片相等

func AssertNoError

func AssertNoError(t *testing.T, err error, msgAndArgs ...any)

AssertNoError 断言没有错误

func AssertNotContains

func AssertNotContains(t *testing.T, s, substr string)

AssertNotContains 断言字符串不包含子串

func AssertToolCallsEqual

func AssertToolCallsEqual(t *testing.T, expected, actual []types.ToolCall)

AssertToolCallsEqual 断言两个工具调用切片相等

func CancelledContext

func CancelledContext() context.Context

CancelledContext 返回已取消的上下文

func CollectStreamChunks

func CollectStreamChunks(ch <-chan llm.StreamChunk) []llm.StreamChunk

CollectStreamChunks 收集流式块到切片

func CollectStreamContent

func CollectStreamContent(ch <-chan llm.StreamChunk) string

CollectStreamContent 收集流式内容到字符串

func CopyMessages

func CopyMessages(messages []types.Message) []types.Message

CopyMessages 深拷贝消息切片

func CopyToolCalls

func CopyToolCalls(toolCalls []types.ToolCall) []types.ToolCall

CopyToolCalls 深拷贝工具调用切片

func MustJSON

func MustJSON(v any) string

MustJSON 将值转换为 JSON 字符串,失败时 panic

func MustParseJSON

func MustParseJSON[T any](s string) T

MustParseJSON 解析 JSON 字符串,失败时 panic

func SendChunksToChannel

func SendChunksToChannel(chunks []llm.StreamChunk) <-chan llm.StreamChunk

SendChunksToChannel 发送块到通道

func TestContext

func TestContext(t *testing.T) context.Context

TestContext 返回带超时的测试上下文

func TestContextWithTimeout

func TestContextWithTimeout(t *testing.T, timeout time.Duration) context.Context

TestContextWithTimeout 返回带自定义超时的测试上下文

func WaitFor

func WaitFor(condition func() bool, timeout time.Duration) bool

WaitFor 等待条件满足或超时

func WaitForChannel

func WaitForChannel[T any](ch <-chan T, timeout time.Duration) (T, bool)

WaitForChannel 等待通道接收或超时

Types

type BenchmarkHelper

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

BenchmarkHelper 基准测试辅助结构

func NewBenchmarkHelper

func NewBenchmarkHelper(b *testing.B) *BenchmarkHelper

NewBenchmarkHelper 创建基准测试辅助

func (*BenchmarkHelper) ReportAllocs

func (h *BenchmarkHelper) ReportAllocs()

ReportAllocs 报告内存分配

func (*BenchmarkHelper) ResetTimer

func (h *BenchmarkHelper) ResetTimer()

ResetTimer 重置计时器

func (*BenchmarkHelper) RunParallel

func (h *BenchmarkHelper) RunParallel(body func())

RunParallel 并行运行基准测试

func (*BenchmarkHelper) StartTimer

func (h *BenchmarkHelper) StartTimer()

StartTimer 启动计时器

func (*BenchmarkHelper) StopTimer

func (h *BenchmarkHelper) StopTimer()

StopTimer 停止计时器

Directories

Path Synopsis
============================================================================= 📦 测试数据工厂 - Agent 测试数据 ============================================================================= 提供预定义的 Agent 配置和状态,用于测试 =============================================================================
============================================================================= 📦 测试数据工厂 - Agent 测试数据 ============================================================================= 提供预定义的 Agent 配置和状态,用于测试 =============================================================================
============================================================================= 🧠 MockMemoryManager - 记忆管理器模拟实现 ============================================================================= 用于测试的记忆管理器模拟,支持消息存储和检索
============================================================================= 🧠 MockMemoryManager - 记忆管理器模拟实现 ============================================================================= 用于测试的记忆管理器模拟,支持消息存储和检索

Jump to

Keyboard shortcuts

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