一键导入
go-testing
Go testing patterns for Beluga AI v2. Use when writing tests, mocks, or benchmarks.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Go testing patterns for Beluga AI v2. Use when writing tests, mocks, or benchmarks.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Documentation writing patterns for Beluga AI v2. Use when creating package docs, tutorials, API guides, or teaching-oriented content.
Go framework design patterns for Beluga AI v2. Use when designing package structure, registries, lifecycle, or creating new packages.
Go interface design with registry, middleware, and hooks for Beluga AI v2. Use when creating interfaces, extension contracts, or adding hooks/middleware.
Implementing providers for Beluga AI v2 registries. Use when creating LLM, embedding, vectorstore, voice, or any other provider.
Go 1.23 iter.Seq2 streaming patterns for Beluga AI v2. Use when implementing streaming, transforms, or backpressure.
| name | go-testing |
| description | Go testing patterns for Beluga AI v2. Use when writing tests, mocks, or benchmarks. |
func TestGenerate(t *testing.T) {
tests := []struct {
name string
input []schema.Message
want *schema.AIMessage
wantErr error
}{
{name: "simple", input: []schema.Message{schema.HumanMessage("hello")}, want: &schema.AIMessage{...}},
{name: "empty input errors", input: nil, wantErr: &core.Error{Code: core.ErrInvalidInput}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := model.Generate(context.Background(), tt.input)
if tt.wantErr != nil { require.Error(t, err); return }
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}
func TestStreamCancellation(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
count := 0
for _, err := range model.Stream(ctx, msgs) {
count++
if count == 2 { cancel() }
if err != nil { assert.ErrorIs(t, err, context.Canceled); break }
}
assert.LessOrEqual(t, count, 3)
}
Location: internal/testutil/mock<package>/. Every mock has configurable function fields + error injection + call counting.
*_test.go alongside source, not in separate dirs.testify/assert (non-fatal) and testify/require (fatal).//go:build integration tag, *_integration_test.go.*_bench_test.go, b.ReportAllocs(), b.RunParallel().var _ Interface = (*Impl)(nil).