From claude-resources
Go testing patterns with stdlib testing package. Table-driven tests, subtests, test helpers, function-based mocks. Extends core/testing with Go-specific implementations.
npx claudepluginhub deandum/claude-resources --plugin go-skillsThis skill uses the workspace's default tool permissions.
Use stdlib `testing` package. No frameworks needed — `testing` + `t.Run` + `t.Helper` is sufficient.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Guides agent creation for Claude Code plugins with file templates, frontmatter specs (name, description, model), triggering examples, system prompts, and best practices.
Use stdlib testing package. No frameworks needed — testing + t.Run + t.Helper is sufficient.
Default pattern for testing multiple cases:
func TestParseAmount(t *testing.T) {
tests := []struct {
name string
input string
want int64
wantErr bool
}{
{name: "whole dollars", input: "42", want: 4200},
{name: "with cents", input: "42.50", want: 4250},
{name: "negative", input: "-10", wantErr: true},
{name: "empty string", input: "", wantErr: true},
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
got, err := ParseAmount(testCase.input)
if testCase.wantErr {
if err == nil { t.Fatal("expected error, got nil") }
return
}
if err != nil { t.Fatalf("unexpected error: %v", err) }
if got != testCase.want {
t.Errorf("ParseAmount(%q) = %d, want %d", testCase.input, got, testCase.want)
}
})
}
}
Guidelines: descriptive name first, got/want convention, t.Fatal for setup failures, t.Error for assertions.
func assertNoError(t *testing.T, err error) {
t.Helper()
if err != nil { t.Fatalf("unexpected error: %v", err) }
}
func assertEqual[T comparable](t *testing.T, got, want T) {
t.Helper()
if got != want { t.Errorf("got %v, want %v", got, want) }
}
func setupTestDB(t *testing.T) *sql.DB {
t.Helper()
db, err := sql.Open("postgres", testDSN)
if err != nil { t.Fatal(err) }
t.Cleanup(func() { db.Close() })
return db
}
Use testdata/ directories for test fixtures (Go ignores them during builds).
Recommended pattern — maximum flexibility per test:
type UserRepositoryFunc struct {
FindByIDFunc func(ctx context.Context, id string) (*User, error)
SaveFunc func(ctx context.Context, user *User) error
}
var _ UserRepository = (*UserRepositoryFunc)(nil)
func (m *UserRepositoryFunc) FindByID(ctx context.Context, id string) (*User, error) {
return m.FindByIDFunc(ctx, id)
}
func (m *UserRepositoryFunc) Save(ctx context.Context, user *User) error {
return m.SaveFunc(ctx, user)
}
Usage:
repo := &UserRepositoryFunc{
FindByIDFunc: func(_ context.Context, id string) (*User, error) {
if id == "user-1" { return &User{ID: "user-1"}, nil }
return nil, ErrNotFound
},
SaveFunc: func(_ context.Context, user *User) error {
savedUser = user // Capture for verification
return nil
},
}
package foo_test for black-box tests (preferred)package foo for white-box tests (when needed)test-integration/ directorytime.Sleep() for sync — use channels or WaitGroupst.Helper() — needed for accurate failure line numberst.Run — use subtestsgo test -race -v ./... passes with no failures or data racest.Helper() called at the start of every test helper function