This skill helps you apply Go testing patterns to write robust tests, mocks, and benchmarks with clear structure and coverage.
npx playbooks add skill lookatitude/beluga-ai --skill go-testing
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).Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.