# Go Table Tests

> Write idiomatic table-driven Go tests that stay offline and follow this repo's conventions.

- Skill: `stacklok/go-table-tests` (Agent Skill)
- Install (CLI): `npx skillmds@latest add stacklok/go-table-tests`
- Raw SKILL.md: https://api.skillmd.com/api/skills/stacklok/go-table-tests/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: stacklok (https://skillmd.com/u/stacklok)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/stacklok/go-table-tests

---


# Go table-driven tests

When adding tests in this codebase:

1. **Stay offline.** Use `mockllm` + `memfs` (or a `t.TempDir()` for file-backed
   adapters). Never hit a live model or the network in a test.
2. **Prefer table-driven cases** for any behaviour with multiple inputs:

   ```go
   func TestThing(t *testing.T) {
       cases := []struct {
           name string
           in   string
           want string
       }{
           {name: "empty", in: "", want: ""},
           {name: "basic", in: "x", want: "X"},
       }
       for _, tc := range cases {
           t.Run(tc.name, func(t *testing.T) {
               if got := Thing(tc.in); got != tc.want {
                   t.Errorf("Thing(%q) = %q, want %q", tc.in, got, tc.want)
               }
           })
       }
   }
   ```

3. **Assert error results, not panics.** Tool-level failures come back as an
   error `ToolResult` (`res.IsError`), not a Go error — check the result.
4. Run the suite with `task test` (which uses `-race`).

