Skip to content

Commit c69a6e5

Browse files
authored
chore: Correct LoggingHookTest timestamp handling. (#386)
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR <!-- add the description of the PR here --> While working on adding support for hook data I noticed unit tests only run correctly in a UTC+0 timezone. This PR formats the timestamp to match how it will appear in the log. Alternatively the logging hook could be changed to always output UTC. ### Related Issues <!-- add here the GitHub issue that this PR resolves if applicable --> ### Notes <!-- any additional notes for this PR --> ### Follow-up Tasks <!-- anything that is related to this PR but not done here should be noted under this section --> <!-- if there is a need for a new issue, please link it here --> ### How to test <!-- if applicable, add testing instructions under this section --> Unit tests should pass when running in a non-UTC timezone. Signed-off-by: Ryan Lamb <[email protected]>
1 parent 9185b76 commit c69a6e5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

test/OpenFeature.Tests/Hooks/LoggingHookTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ public async Task BeforeAsync_With_EvaluationContext_Generates_Correct_Log_Messa
8989

9090
var clientMetadata = new ClientMetadata("client", "1.0.0");
9191
var providerMetadata = new Metadata("provider");
92+
var timestamp = DateTime.Parse("2025-01-01T11:00:00.0000000Z");
9293
var evaluationContext = EvaluationContext.Builder()
9394
.Set("key_1", "value")
9495
.Set("key_2", false)
9596
.Set("key_3", 1.531)
9697
.Set("key_4", 42)
97-
.Set("key_5", DateTime.Parse("2025-01-01T11:00:00.0000000Z"))
98+
.Set("key_5", timestamp)
9899
.Build();
99100

100101
var context = new HookContext<bool>("test", false, FlagValueType.Object, clientMetadata,
@@ -116,7 +117,7 @@ public async Task BeforeAsync_With_EvaluationContext_Generates_Correct_Log_Messa
116117
() => Assert.Contains("key_2:False", record.Message),
117118
() => Assert.Contains("key_3:1.531", record.Message),
118119
() => Assert.Contains("key_4:42", record.Message),
119-
() => Assert.Contains("key_5:2025-01-01T11:00:00.0000000+00:00", record.Message)
120+
() => Assert.Contains($"key_5:{timestamp:O}", record.Message)
120121
);
121122
}
122123

@@ -225,12 +226,14 @@ public async Task ErrorAsync_With_EvaluationContext_Generates_Correct_Log_Messag
225226

226227
var clientMetadata = new ClientMetadata("client", "1.0.0");
227228
var providerMetadata = new Metadata("provider");
229+
230+
var timestamp = DateTime.Parse("2099-01-01T01:00:00.0000000Z");
228231
var evaluationContext = EvaluationContext.Builder()
229232
.Set("key_1", " ")
230233
.Set("key_2", true)
231234
.Set("key_3", 0.002154)
232235
.Set("key_4", -15)
233-
.Set("key_5", DateTime.Parse("2099-01-01T01:00:00.0000000Z"))
236+
.Set("key_5", timestamp)
234237
.Build();
235238

236239
var context = new HookContext<bool>("test", false, FlagValueType.Object, clientMetadata,
@@ -254,7 +257,7 @@ public async Task ErrorAsync_With_EvaluationContext_Generates_Correct_Log_Messag
254257
() => Assert.Contains("key_2:True", record.Message),
255258
() => Assert.Contains("key_3:0.002154", record.Message),
256259
() => Assert.Contains("key_4:-15", record.Message),
257-
() => Assert.Contains("key_5:2099-01-01T01:00:00.0000000+00:00", record.Message)
260+
() => Assert.Contains($"key_5:{timestamp:O}", record.Message)
258261
);
259262
}
260263

0 commit comments

Comments
 (0)