[]struct {
name string
input <type> // or slice/args
fn <func type> // if applicable
want <type> // expected result
}
- Struct must have
name,input/slice/args, andwantfields. - No
run func(t *testing.T)field — assertion logic goes in the loop body. - No
t.Runnaming tricks — use descriptive case names for readability. - One shared
forloop per test function. No nested subtables.
Use assert.Eq and assert.EqSlice from github.com/iamgoroot/gofu/test/assert:
assert.Eq(t, got, want)— for scalar comparisons (int, string, bool, len checks)assert.EqSlice(t, got, want)— for full slice comparison (usesslices.Equal)
Assertion is inlined in the t.Run body:
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.EqSlice(t, tt.input.Filter(tt.fn), tt.want)
})
}t.Parallel()at top of test function only, not per-case.- No shared test helpers or closures declared inside test functions — use
test/assert.