Claude
Skill
go-testing
Trigger: Go tests, go test coverage, Bubbletea teatest, golden files. Apply focused Go testing patterns.
Virus-scanned
Reviewed automatically before listing.
Download
gentleman-programming-gentle-ai-internal_assets_skills_go-testing-d2e3443.zip · 2 KB
Install
skills CLI
npx skills add https://github.com/Gentleman-Programming/gentle-ai/tree/main/internal/assets/skills/go-testing
Claude Code
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install gentleman-programming-gentle-ai@llmmart
Git
git clone https://github.com/Gentleman-Programming/gentle-ai.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole gentleman-programming/gentle-ai collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Activation Contract
Load this skill when writing or reviewing Go tests, adding coverage, testing Bubbletea/TUI flows, using teatest, or updating golden files.
Hard Rules
- Prefer table-driven tests for multiple cases; use
t.Run(tt.name, ...). - Test behavior and state transitions, not implementation trivia.
- Use
t.TempDir()for filesystem tests; never rely on a real home directory. - Keep integration tests skippable with
testing.Short()when they run external commands or slow flows. - For Bubbletea, test
Model.Update()directly for state changes; useteatestonly for interactive flows. - Golden files must be deterministic; update only through the repo's
-updatepath and rerun tests without-update. - Use small mocks/interfaces around system or command execution boundaries.
Decision Gates
| Target | Test pattern |
|---|---|
| Pure function or parser | Table-driven unit test. |
| Error behavior | Explicit success and failure cases. |
| File operations | t.TempDir() plus focused assertions. |
| TUI state transition | Direct Model.Update() call with tea.Msg. |
| Full TUI interaction | teatest.NewTestModel(). |
| Rendered output | Golden file test. |
| Real external command | Integration test; skip in -short. |
Execution Steps
- Identify behavior under test and the smallest public boundary that proves it.
- Choose the test pattern from the decision gate.
- Name cases by scenario, not input mechanics.
- Assert outputs, errors, state, and side effects explicitly.
- Run the narrow package test first, then the relevant broader suite.
- For golden updates: run with
-update, inspect diff, then rerun without-update.
Output Contract
Report test files changed, scenarios covered, commands executed, golden files updated, and any skipped integration scope.
References
- references/examples.md — compact table-driven, Bubbletea, teatest, golden, and command examples.
Files (gentle-ai)
-
references
-
examples.md 2 KB
# Go Testing Examples ## Table-Driven Test ```go func TestProcessInput(t *testing.T) { tests := []struct { name string input string want string wantErr bool }{ {name: "valid input", input: "hello", want: "HELLO"}, {name: "empty input", input: "", wantErr: true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := ProcessInput(tt.input) if (err != nil) != tt.wantErr { t.Fatalf("err = %v, wantErr %v", err, tt.wantErr) } if got != tt.want { t.Fatalf("got %q, want %q", got, tt.want) } }) } } ``` ## Bubbletea State Transition ```go func TestModelUpdateEnter(t *testing.T) { m := NewModel() next, _ := m.Update(tea.KeyMsg{Type: tea.KeyEnter}) got := next.(Model) if got.Screen != ScreenMainMenu { t.Fatalf("screen = %v, want %v", got.Screen, ScreenMainMenu) } } ``` ## Teatest Flow ```go func TestInteractiveFlow(t *testing.T) { tm := teatest.NewTestModel(t, NewModel()) tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) tm.WaitFinished(t, teatest.WithDuration(time.Second)) final := tm.FinalModel(t).(Model) if final.Screen != ExpectedScreen { t.Fatalf("screen = %v, want %v", final.Screen, ExpectedScreen) } } ``` ## Golden File Pattern ```go var update = flag.Bool("update", false, "update golden files") func assertGolden(t *testing.T, path string, got string) { t.Helper() if *update { if err := os.WriteFile(path, []byte(got), 0o644); err != nil { t.Fatal(err) } } want, err := os.ReadFile(path) if err != nil { t.Fatal(err) } if got != string(want) { t.Fatalf("golden mismatch for %s", path) } } ``` ## Commands ```bash go test ./... go test -v ./internal/tui/... go test -run TestNavigation ./internal/tui go test -cover ./... go test ./internal/components -update go test -short ./... ```
-
-
SKILL.md 2.1 KB
--- name: go-testing description: "Trigger: Go tests, go test coverage, Bubbletea teatest, golden files. Apply focused Go testing patterns." license: Apache-2.0 metadata: author: gentleman-programming version: "1.0" --- ## Activation Contract Load this skill when writing or reviewing Go tests, adding coverage, testing Bubbletea/TUI flows, using `teatest`, or updating golden files. ## Hard Rules - Prefer table-driven tests for multiple cases; use `t.Run(tt.name, ...)`. - Test behavior and state transitions, not implementation trivia. - Use `t.TempDir()` for filesystem tests; never rely on a real home directory. - Keep integration tests skippable with `testing.Short()` when they run external commands or slow flows. - For Bubbletea, test `Model.Update()` directly for state changes; use `teatest` only for interactive flows. - Golden files must be deterministic; update only through the repo's `-update` path and rerun tests without `-update`. - Use small mocks/interfaces around system or command execution boundaries. ## Decision Gates | Target | Test pattern | |---|---| | Pure function or parser | Table-driven unit test. | | Error behavior | Explicit success and failure cases. | | File operations | `t.TempDir()` plus focused assertions. | | TUI state transition | Direct `Model.Update()` call with `tea.Msg`. | | Full TUI interaction | `teatest.NewTestModel()`. | | Rendered output | Golden file test. | | Real external command | Integration test; skip in `-short`. | ## Execution Steps 1. Identify behavior under test and the smallest public boundary that proves it. 2. Choose the test pattern from the decision gate. 3. Name cases by scenario, not input mechanics. 4. Assert outputs, errors, state, and side effects explicitly. 5. Run the narrow package test first, then the relevant broader suite. 6. For golden updates: run with `-update`, inspect diff, then rerun without `-update`. ## Output Contract Report test files changed, scenarios covered, commands executed, golden files updated, and any skipped integration scope. ## References - [references/examples.md](references/examples.md) — compact table-driven, Bubbletea, teatest, golden, and command examples.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.