Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/api/api/api_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,9 @@ func TestGrpcGetEvaluationsValidation(t *testing.T) {
"authorization": []string{"test-key"},
})
actual, err := gs.GetEvaluations(ctx, p.input)
if p.expected != nil && actual != nil {
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, actual.Evaluations)
}
assert.Equal(t, p.expected, actual, "%s", p.desc)
assert.Equal(t, p.expectedErr, err, "%s", p.desc)
})
Expand Down Expand Up @@ -2410,6 +2413,7 @@ func TestGrpcGetEvaluationsZeroFeature(t *testing.T) {
"authorization": []string{"test-key"},
})
actual, err := gs.GetEvaluations(ctx, p.input)
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, actual.Evaluations)
assert.Equal(t, p.expected, actual, "%s", p.desc)
assert.Equal(t, p.expected.State, actual.State, "%s", p.desc)
assert.Equal(t, p.expectedErr, err, "%s", p.desc)
Expand Down Expand Up @@ -4959,6 +4963,18 @@ func emptyUserEvaluations(t *testing.T) *featureproto.UserEvaluations {
}
}

// CreatedAt is stamped by the service while the test runs, so it can differ from the value
// the expectation was built with and make a plain Equal flaky. Check it only loosely, then
// align expected with it so the remaining fields are still compared exactly.
func normalizeUserEvaluationsCreatedAt(t *testing.T, expected, actual *featureproto.UserEvaluations) {
t.Helper()
if expected == nil || actual == nil {
return
}
assert.InDelta(t, time.Now().Unix(), actual.CreatedAt, 5)
expected.CreatedAt = actual.CreatedAt
}

func TestGrpcListFeatures(t *testing.T) {
t.Parallel()
mockController := gomock.NewController(t)
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ func TestGetEvaluationsValidation(t *testing.T) {
decoded := decodeSuccessResponse(t, actual.Body)
err := json.Unmarshal(decoded, &respBody)
assert.NoError(t, err)
// FIXME: This is a flaky test. CreateAt may not be equal ocasionally.
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, respBody.Evaluations)
assert.Equal(t, p.expected, &respBody, "%s", p.desc)
}
}
Expand Down Expand Up @@ -779,6 +779,7 @@ func TestGetEvaluationsZeroFeature(t *testing.T) {
decoded := decodeSuccessResponse(t, actual.Body)
err := json.Unmarshal(decoded, &respBody)
assert.NoError(t, err)
normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, respBody.Evaluations)
assert.Equal(t, p.expected, &respBody, "%s", p.desc)
}
}
Expand Down
Loading