Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.09 KB

File metadata and controls

39 lines (29 loc) · 1.09 KB

Test Rules

Table-Driven Tests

[]struct {
    name  string
    input <type>       // or slice/args
    fn    <func type>  // if applicable
    want  <type>       // expected result
}
  • Struct must have name, input/slice/args, and want fields.
  • No run func(t *testing.T) field — assertion logic goes in the loop body.
  • No t.Run naming tricks — use descriptive case names for readability.
  • One shared for loop per test function. No nested subtables.

Assertions

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 (uses slices.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)
    })
}

Conventions

  • t.Parallel() at top of test function only, not per-case.
  • No shared test helpers or closures declared inside test functions — use test/assert.