🎯 Areas for Improvement
1. No Testify — Manual Assertions Everywhere
The file does not import github.com/stretchr/testify/assert or require. Every assertion uses raw t.Errorf with manual guards and early returns.
Current pattern (repeated ~40+ times):
if tt.expectError {
if err == nil {
t.Errorf("parseTimeDelta(%q) expected error but got none", tt.input)
return
}
if tt.errorMsg != "" && !containsString(err.Error(), tt.errorMsg) {
t.Errorf("parseTimeDelta(%q) error = %v, want to contain %v", tt.input, err.Error(), tt.errorMsg)
}
} else {
if err != nil {
t.Errorf("parseTimeDelta(%q) unexpected error: %v", tt.input, err)
return
}
if result == nil {
t.Errorf("parseTimeDelta(%q) returned nil result", tt.input)
return
}
if result.Days != tt.expected.Days || result.Hours != tt.expected.Hours || result.Minutes != tt.expected.Minutes {
t.Errorf("parseTimeDelta(%q) = {Days: %d, Hours: %d, Minutes: %d}, ...")
}
}
Recommended (testify):
if tt.expectError {
require.Error(t, err, "parseTimeDelta(%q) should return an error", tt.input)
if tt.errorMsg != "" {
assert.Contains(t, err.Error(), tt.errorMsg, "error message should contain expected substring")
}
} else {
require.NoError(t, err, "parseTimeDelta(%q) should not return an error", tt.input)
require.NotNil(t, result, "parseTimeDelta(%q) should return a non-nil result", tt.input)
assert.Equal(t, tt.expected, result, "parseTimeDelta(%q) result mismatch", tt.input)
}
This reduces ~12 lines to ~6 and gives far better diff output on failure via assert.Equal.
2. Custom containsString Helper — Replace with assert.Contains
The file defines its own helper at line 730:
func containsString(s, substr string) bool {
return strings.Contains(s, substr)
}
This is used in 5 places. With testify, it can be eliminated entirely:
// ❌ CURRENT
if tt.errorMsg != "" && !containsString(err.Error(), tt.errorMsg) {
t.Errorf("...")
}
// ✅ IMPROVED
assert.Contains(t, err.Error(), tt.errorMsg, "error should contain expected message")
3. Struct Field Comparison — Replace with assert.Equal
Multiple tests manually compare individual struct fields instead of comparing the whole struct:
// ❌ CURRENT — verbose, misses Weeks/Months fields in some places
if result.Days != tt.expected.Days || result.Hours != tt.expected.Hours || result.Minutes != tt.expected.Minutes {
t.Errorf("parseTimeDelta(%q) = {Days: %d, Hours: %d, Minutes: %d}, want {Days: %d, Hours: %d, Minutes: %d}",
tt.input, result.Days, result.Hours, result.Minutes, tt.expected.Days, tt.expected.Hours, tt.expected.Minutes)
}
// ✅ IMPROVED — simpler, automatically compares all fields, better diff
assert.Equal(t, tt.expected, result, "parseTimeDelta(%q) result mismatch", tt.input)
Note: TestParseTimeDelta only compares Days, Hours, Minutes but not Weeks or Months — assert.Equal would catch regressions in those fields automatically.
4. Missing require.* for Critical Guards
When an error is not expected and err != nil, the test uses t.Errorf + return instead of require.NoError. The require pattern is more idiomatic and avoids the manual return:
// ❌ CURRENT
if err != nil {
t.Errorf("parseAbsoluteDateTime(%q) unexpected error: %v", tt.input, err)
return
}
// ✅ IMPROVED — stops subtest immediately on failure, no manual return
require.NoError(t, err, "parseAbsoluteDateTime(%q) should not error", tt.input)
5. TestParseAbsoluteDateTime — Repeated Validation Logic
The result parsing in TestParseAbsoluteDateTime is repeated inline for each subtest (parse result, check day, check month, check year separately). This could use a helper or assert.Equal on a struct:
// ✅ IMPROVED — parse once, assert once
require.NoError(t, err, "should parse absolute date time")
parsed, parseErr := time.Parse("2006-01-02 15:04:05", result)
require.NoError(t, parseErr, "result should be a valid timestamp: %s", result)
assert.Equal(t, tt.expectedYear, parsed.Year(), "year mismatch")
assert.Equal(t, tt.expectedMonth, parsed.Month(), "month mismatch")
assert.Equal(t, tt.expectedDay, parsed.Day(), "day mismatch")
Overview
The test file
pkg/workflow/time_delta_test.go(1284 lines, 11 test functions) has been selected for quality improvement by the Testify Uber Super Expert. This file has zero testify usage — it relies entirely on rawt.Errorf/t.Errorcalls, manual equality checks, and a customcontainsStringhelper. Converting to testify would significantly improve readability, error messages, and consistency with the rest of the codebase.Current State
pkg/workflow/time_delta_test.gopkg/workflow/time_delta.goassertorrequireimportedTest Quality Analysis
Strengths ✅
t.Run()throughout — this is the right pattern🎯 Areas for Improvement
1. No Testify — Manual Assertions Everywhere
The file does not import
github.com/stretchr/testify/assertorrequire. Every assertion uses rawt.Errorfwith manual guards and early returns.Current pattern (repeated ~40+ times):
Recommended (testify):
This reduces ~12 lines to ~6 and gives far better diff output on failure via
assert.Equal.2. Custom
containsStringHelper — Replace withassert.ContainsThe file defines its own helper at line 730:
This is used in 5 places. With testify, it can be eliminated entirely:
3. Struct Field Comparison — Replace with
assert.EqualMultiple tests manually compare individual struct fields instead of comparing the whole struct:
Note:
TestParseTimeDeltaonly comparesDays,Hours,Minutesbut notWeeksorMonths—assert.Equalwould catch regressions in those fields automatically.4. Missing
require.*for Critical GuardsWhen an error is not expected and
err != nil, the test usest.Errorf+returninstead ofrequire.NoError. Therequirepattern is more idiomatic and avoids the manualreturn:5.
TestParseAbsoluteDateTime— Repeated Validation LogicThe result parsing in
TestParseAbsoluteDateTimeis repeated inline for each subtest (parse result, check day, check month, check year separately). This could use a helper orassert.Equalon a struct:📋 Implementation Guidelines
Steps
Add testify imports:
Remove the
containsStringhelper function (line 730)Replace all
t.Errorf/t.Errorpatterns withassert.*/require.*throughout all 11 test functionsReplace manual struct field comparisons with
assert.Equal(t, tt.expected, result, ...)Replace
!containsString(err.Error(), tt.errorMsg)withassert.Contains(t, err.Error(), tt.errorMsg, ...)Priority Order
containsStringrequire.NoError/require.Errorassert.EqualTesting Commands
Reference
scratchpad/testing.mdAcceptance Criteria
github.com/stretchr/testify/assertandrequireimportedcontainsStringhelper removedt.Errorf/t.Errorpatterns replaced withassert.*/require.*assert.Equal(t, tt.expected, result, ...)instead of field-by-field checksassert.Containsinstead of!containsString(...)make test-unitPriority: Medium
Effort: Medium (1284-line file, 11 functions, ~40+ assertion sites)
Expected Impact: Shorter test code, richer failure output, consistency with codebase standards
Files Involved:
pkg/workflow/time_delta_test.gopkg/workflow/time_delta.goReferences: §25636010680