Skip to content

Commit a98334e

Browse files
fix: Address issue with newline characters when running Logging Hook Unit Tests on linux (#374)
<!-- 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 --> I noticed when I ran the LoggingHook unit tests on a WSL Ubuntu instance the some tests fails due to new line characters. It appears I never normalized or excluded newline characters when asserting equal ![image](https://github.com/user-attachments/assets/91bceb1b-41be-4f5c-b330-874ef614c163) I also removed the `Assert.Contains` snippets as the content and layout of the log message is asserted in the other tests. This Assert method does not have an overload for ignoring new line characters I assume the GitHub CI runner may be ignore the line endings by default? ### 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 --> Signed-off-by: Kyle Julian <[email protected]>
1 parent 4977542 commit a98334e

File tree

1 file changed

+36
-45
lines changed

1 file changed

+36
-45
lines changed

test/OpenFeature.Tests/Hooks/LoggingHookTests.cs

+36-45
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public async Task BeforeAsync_Without_EvaluationContext_Generates_Debug_Log()
4444
DefaultValue:False
4545
4646
""",
47-
record.Message);
47+
record.Message,
48+
ignoreLineEndingDifferences: true
49+
);
4850
}
4951

5052
[Fact]
@@ -74,7 +76,9 @@ public async Task BeforeAsync_Without_EvaluationContext_Generates_Correct_Log_Me
7476
DefaultValue:False
7577
7678
""",
77-
record.Message);
79+
record.Message,
80+
ignoreLineEndingDifferences: true
81+
);
7882
}
7983

8084
[Fact]
@@ -107,15 +111,6 @@ public async Task BeforeAsync_With_EvaluationContext_Generates_Correct_Log_Messa
107111
var record = logger.LatestRecord;
108112
Assert.Equal(LogLevel.Debug, record.Level);
109113

110-
Assert.Contains(
111-
"""
112-
Before Flag Evaluation Domain:client
113-
ProviderName:provider
114-
FlagKey:test
115-
DefaultValue:False
116-
Context:
117-
""",
118-
record.Message);
119114
Assert.Multiple(
120115
() => Assert.Contains("key_1:value", record.Message),
121116
() => Assert.Contains("key_2:False", record.Message),
@@ -157,7 +152,9 @@ public async Task BeforeAsync_With_No_EvaluationContext_Generates_Correct_Log_Me
157152
Context:
158153
159154
""",
160-
record.Message);
155+
record.Message,
156+
ignoreLineEndingDifferences: true
157+
);
161158
}
162159

163160
[Fact]
@@ -215,7 +212,9 @@ public async Task ErrorAsync_Without_EvaluationContext_Generates_Correct_Log_Mes
215212
DefaultValue:False
216213
217214
""",
218-
record.Message);
215+
record.Message,
216+
ignoreLineEndingDifferences: true
217+
);
219218
}
220219

221220
[Fact]
@@ -250,15 +249,6 @@ public async Task ErrorAsync_With_EvaluationContext_Generates_Correct_Log_Messag
250249
var record = logger.LatestRecord;
251250
Assert.Equal(LogLevel.Error, record.Level);
252251

253-
Assert.Contains(
254-
"""
255-
Error during Flag Evaluation Domain:client
256-
ProviderName:provider
257-
FlagKey:test
258-
DefaultValue:False
259-
Context:
260-
""",
261-
record.Message);
262252
Assert.Multiple(
263253
() => Assert.Contains("key_1: ", record.Message),
264254
() => Assert.Contains("key_2:True", record.Message),
@@ -301,7 +291,9 @@ public async Task ErrorAsync_With_No_EvaluationContext_Generates_Correct_Log_Mes
301291
Context:
302292
303293
""",
304-
record.Message);
294+
record.Message,
295+
ignoreLineEndingDifferences: true
296+
);
305297
}
306298

307299
[Fact]
@@ -358,7 +350,9 @@ public async Task AfterAsync_Without_EvaluationContext_Generates_Correct_Log_Mes
358350
DefaultValue:False
359351
360352
""",
361-
record.Message);
353+
record.Message,
354+
ignoreLineEndingDifferences: true
355+
);
362356
}
363357

364358
[Fact]
@@ -393,16 +387,6 @@ public async Task AfterAsync_With_EvaluationContext_Generates_Correct_Log_Messag
393387
var record = logger.LatestRecord;
394388
Assert.Equal(LogLevel.Debug, record.Level);
395389

396-
Assert.Contains(
397-
"""
398-
After Flag Evaluation Domain:client
399-
ProviderName:provider
400-
FlagKey:test
401-
DefaultValue:False
402-
Context:
403-
""",
404-
record.Message);
405-
406390
// .NET Framework uses G15 formatter on double.ToString
407391
// .NET uses G17 formatter on double.ToString
408392
#if NET462
@@ -452,7 +436,9 @@ public async Task AfterAsync_With_No_EvaluationContext_Generates_Correct_Log_Mes
452436
Context:
453437
454438
""",
455-
record.Message);
439+
record.Message,
440+
ignoreLineEndingDifferences: true
441+
);
456442
}
457443

458444
[Fact]
@@ -499,8 +485,9 @@ public async Task With_Structure_Type_In_Context_Returns_Qualified_Name_Of_Value
499485
key_1:OpenFeature.Model.Value
500486
501487
""",
502-
message
503-
);
488+
message,
489+
ignoreLineEndingDifferences: true
490+
);
504491
}
505492

506493
[Fact]
@@ -539,8 +526,9 @@ public async Task Without_Domain_Returns_Missing()
539526
key_1:True
540527
541528
""",
542-
message
543-
);
529+
message,
530+
ignoreLineEndingDifferences: true
531+
);
544532
}
545533

546534
[Fact]
@@ -579,8 +567,9 @@ public async Task Without_Provider_Returns_Missing()
579567
key_1:True
580568
581569
""",
582-
message
583-
);
570+
message,
571+
ignoreLineEndingDifferences: true
572+
);
584573
}
585574

586575
[Fact]
@@ -619,8 +608,9 @@ public async Task Without_DefaultValue_Returns_Missing()
619608
key_1:True
620609
621610
""",
622-
message
623-
);
611+
message,
612+
ignoreLineEndingDifferences: true
613+
);
624614
}
625615

626616
[Fact]
@@ -659,8 +649,9 @@ public async Task Without_EvaluationContextValue_Returns_Nothing()
659649
key_1:
660650
661651
""",
662-
message
663-
);
652+
message,
653+
ignoreLineEndingDifferences: true
654+
);
664655
}
665656

666657
private static string NormalizeLogRecord(FakeLogRecord record)

0 commit comments

Comments
 (0)