Description
Table-driven tests use two competing naming conventions: 97.7% use tests/tt, while 2.3% use testCases/tc. This inconsistency creates unnecessary cognitive load during code review and maintenance.
Problem
Statistics:
- 1,394 instances use
tests := []struct with for _, tt := range tests
- 33 instances use
testCases := []struct with for _, tc := range testCases
Developers must context-switch between conventions, slowing code reviews and maintenance.
Suggested Changes
Standardize on tests/tt pattern (majority convention) via automated refactoring:
Before (minority pattern in 33 files)
testCases := []struct {
name string
input int
expected int
}{
{name: "positive", input: 5, expected: 5},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := myFunc(tc.input)
require.Equal(t, tc.expected, result)
})
}
After (standard pattern)
tests := []struct {
name string
input int
expected int
}{
{name: "positive", input: 5, expected: 5},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := myFunc(tt.input)
require.Equal(t, tt.expected, result)
})
}
Implementation Steps
-
Find files using testCases pattern:
rg "testCases := \[\]struct" --type go -g "*_test.go" --files-with-matches
-
Semi-automated refactor (manual review required for scoped variables):
- Replace
testCases := []struct → tests := []struct
- Replace
for _, tc := range testCases → for _, tt := range tests
- Replace all
tc. → tt. within each test function scope
-
Add linter rule - Use golangci-lint varnamelen to prefer tt over tc
-
Document - Add standard to CONTRIBUTING.md
Files Affected
33 test files across the codebase (identified via ripgrep search)
Success Criteria
Source
Extracted from Sergo Report: Table-Driven Test & Init Function Hygiene Analysis - 2026-01-30
Priority
Medium - Code consistency improvement, low risk
Estimated Effort
Small (1 hour) - Mostly automated find-replace with manual verification
AI generated by Discussion Task Miner - Code Quality Improvement Agent
Description
Table-driven tests use two competing naming conventions: 97.7% use
tests/tt, while 2.3% usetestCases/tc. This inconsistency creates unnecessary cognitive load during code review and maintenance.Problem
Statistics:
tests := []structwithfor _, tt := range teststestCases := []structwithfor _, tc := range testCasesDevelopers must context-switch between conventions, slowing code reviews and maintenance.
Suggested Changes
Standardize on
tests/ttpattern (majority convention) via automated refactoring:Before (minority pattern in 33 files)
After (standard pattern)
Implementation Steps
Find files using testCases pattern:
Semi-automated refactor (manual review required for scoped variables):
testCases := []struct→tests := []structfor _, tc := range testCases→for _, tt := range teststc.→tt.within each test function scopeAdd linter rule - Use golangci-lint
varnamelento preferttovertcDocument - Add standard to CONTRIBUTING.md
Files Affected
33 test files across the codebase (identified via ripgrep search)
Success Criteria
ttovertcSource
Extracted from Sergo Report: Table-Driven Test & Init Function Hygiene Analysis - 2026-01-30
Priority
Medium - Code consistency improvement, low risk
Estimated Effort
Small (1 hour) - Mostly automated find-replace with manual verification