Skip to content

Commit 65d68e3

Browse files
s35560claude
andcommitted
test(api): address review on normalizeUserEvaluationsCreatedAt
Explain why the helper exists (the service stamps CreatedAt mid-test, so a plain Equal is flaky) instead of restating what it does, and drop the msgAndArgs parameter: t.Helper() already points at the caller line. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 19bf6ec commit 65d68e3

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

pkg/api/api/api_grpc_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,7 @@ func TestGrpcGetEvaluationsValidation(t *testing.T) {
23602360
})
23612361
actual, err := gs.GetEvaluations(ctx, p.input)
23622362
if p.expected != nil && actual != nil {
2363-
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, actual.Evaluations, "%s", p.desc)
2363+
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, actual.Evaluations)
23642364
}
23652365
assert.Equal(t, p.expected, actual, "%s", p.desc)
23662366
assert.Equal(t, p.expectedErr, err, "%s", p.desc)
@@ -2413,7 +2413,7 @@ func TestGrpcGetEvaluationsZeroFeature(t *testing.T) {
24132413
"authorization": []string{"test-key"},
24142414
})
24152415
actual, err := gs.GetEvaluations(ctx, p.input)
2416-
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, actual.Evaluations, "%s", p.desc)
2416+
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, actual.Evaluations)
24172417
assert.Equal(t, p.expected, actual, "%s", p.desc)
24182418
assert.Equal(t, p.expected.State, actual.State, "%s", p.desc)
24192419
assert.Equal(t, p.expectedErr, err, "%s", p.desc)
@@ -4963,17 +4963,15 @@ func emptyUserEvaluations(t *testing.T) *featureproto.UserEvaluations {
49634963
}
49644964
}
49654965

4966-
// normalizeUserEvaluationsCreatedAt asserts CreatedAt is roughly now, then aligns expected so Equal stays stable.
4967-
func normalizeUserEvaluationsCreatedAt(
4968-
t *testing.T,
4969-
expected, actual *featureproto.UserEvaluations,
4970-
msgAndArgs ...interface{},
4971-
) {
4966+
// CreatedAt is stamped by the service while the test runs, so it can differ from the value
4967+
// the expectation was built with and make a plain Equal flaky. Check it only loosely, then
4968+
// align expected with it so the remaining fields are still compared exactly.
4969+
func normalizeUserEvaluationsCreatedAt(t *testing.T, expected, actual *featureproto.UserEvaluations) {
49724970
t.Helper()
49734971
if expected == nil || actual == nil {
49744972
return
49754973
}
4976-
assert.InDelta(t, time.Now().Unix(), actual.CreatedAt, 5, msgAndArgs...)
4974+
assert.InDelta(t, time.Now().Unix(), actual.CreatedAt, 5)
49774975
expected.CreatedAt = actual.CreatedAt
49784976
}
49794977

pkg/api/api/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ func TestGetEvaluationsValidation(t *testing.T) {
716716
decoded := decodeSuccessResponse(t, actual.Body)
717717
err := json.Unmarshal(decoded, &respBody)
718718
assert.NoError(t, err)
719-
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, respBody.Evaluations, "%s", p.desc)
719+
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, respBody.Evaluations)
720720
assert.Equal(t, p.expected, &respBody, "%s", p.desc)
721721
}
722722
}
@@ -779,7 +779,7 @@ func TestGetEvaluationsZeroFeature(t *testing.T) {
779779
decoded := decodeSuccessResponse(t, actual.Body)
780780
err := json.Unmarshal(decoded, &respBody)
781781
assert.NoError(t, err)
782-
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, respBody.Evaluations, "%s", p.desc)
782+
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, respBody.Evaluations)
783783
assert.Equal(t, p.expected, &respBody, "%s", p.desc)
784784
}
785785
}

0 commit comments

Comments
 (0)