Documentation
¶
Overview ¶
Package testutil 提供 AgentFlow 测试的共享工具和辅助函数。
包含 context helpers、assertion helpers、async helpers、 data helpers、stream helpers 以及共享的 mock 和 fixture 工厂。 所有测试应优先使用此包中的工具,而非重复实现。
testutil 通用测试辅助与断言工具。
提供上下文构造、消息断言及异步等待断言等能力。
Index ¶
- func AssertContains(t *testing.T, s, substr string)
- func AssertError(t *testing.T, err error, msgAndArgs ...any)
- func AssertEventuallyEqual(t *testing.T, expected any, getter func() any, timeout time.Duration)
- func AssertEventuallyTrue(t *testing.T, condition func() bool, timeout time.Duration)
- func AssertJSONEqual(t *testing.T, expected, actual any)
- func AssertMessagesEqual(t *testing.T, expected, actual []types.Message)
- func AssertNoError(t *testing.T, err error, msgAndArgs ...any)
- func AssertNotContains(t *testing.T, s, substr string)
- func AssertToolCallsEqual(t *testing.T, expected, actual []types.ToolCall)
- func CancelledContext() context.Context
- func CollectStreamChunks(ch <-chan llm.StreamChunk) []llm.StreamChunk
- func CollectStreamContent(ch <-chan llm.StreamChunk) string
- func CopyMessages(messages []types.Message) []types.Message
- func CopyToolCalls(toolCalls []types.ToolCall) []types.ToolCall
- func MustJSON(v any) string
- func MustParseJSON[T any](s string) T
- func SendChunksToChannel(chunks []llm.StreamChunk) <-chan llm.StreamChunk
- func TestContext(t *testing.T) context.Context
- func TestContextWithTimeout(t *testing.T, timeout time.Duration) context.Context
- func WaitFor(condition func() bool, timeout time.Duration) bool
- func WaitForChannel[T any](ch <-chan T, timeout time.Duration) (T, bool)
- type BenchmarkHelper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEventuallyEqual ¶
AssertEventuallyEqual 断言值最终相等
func AssertEventuallyTrue ¶
AssertEventuallyTrue 断言条件最终为真
func AssertJSONEqual ¶
AssertJSONEqual 断言两个值的 JSON 表示相等
func AssertMessagesEqual ¶
AssertMessagesEqual 断言两个消息切片相等
func AssertNoError ¶
AssertNoError 断言没有错误
func AssertNotContains ¶
AssertNotContains 断言字符串不包含子串
func AssertToolCallsEqual ¶
AssertToolCallsEqual 断言两个工具调用切片相等
func CollectStreamChunks ¶
func CollectStreamChunks(ch <-chan llm.StreamChunk) []llm.StreamChunk
CollectStreamChunks 收集流式块到切片
func CollectStreamContent ¶
func CollectStreamContent(ch <-chan llm.StreamChunk) string
CollectStreamContent 收集流式内容到字符串
func CopyMessages ¶
CopyMessages 深拷贝消息切片
func CopyToolCalls ¶
CopyToolCalls 深拷贝工具调用切片
func SendChunksToChannel ¶
func SendChunksToChannel(chunks []llm.StreamChunk) <-chan llm.StreamChunk
SendChunksToChannel 发送块到通道
func TestContextWithTimeout ¶
TestContextWithTimeout 返回带自定义超时的测试上下文
Types ¶
type BenchmarkHelper ¶
type BenchmarkHelper struct {
// contains filtered or unexported fields
}
BenchmarkHelper 基准测试辅助结构
func NewBenchmarkHelper ¶
func NewBenchmarkHelper(b *testing.B) *BenchmarkHelper
NewBenchmarkHelper 创建基准测试辅助
func (*BenchmarkHelper) RunParallel ¶
func (h *BenchmarkHelper) RunParallel(body func())
RunParallel 并行运行基准测试