Skip to content

Commit

Permalink
fix: Address issue with newline characters when running Logging Hook …
Browse files Browse the repository at this point in the history
…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 <38759683+kylejuliandev@users.noreply.github.com>
  • Loading branch information
kylejuliandev authored Feb 17, 2025
1 parent 4977542 commit a98334e
Showing 1 changed file with 36 additions and 45 deletions.
81 changes: 36 additions & 45 deletions test/OpenFeature.Tests/Hooks/LoggingHookTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public async Task BeforeAsync_Without_EvaluationContext_Generates_Debug_Log()
DefaultValue:False
""",
record.Message);
record.Message,
ignoreLineEndingDifferences: true
);
}

[Fact]
Expand Down Expand Up @@ -74,7 +76,9 @@ public async Task BeforeAsync_Without_EvaluationContext_Generates_Correct_Log_Me
DefaultValue:False
""",
record.Message);
record.Message,
ignoreLineEndingDifferences: true
);
}

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

Assert.Contains(
"""
Before Flag Evaluation Domain:client
ProviderName:provider
FlagKey:test
DefaultValue:False
Context:
""",
record.Message);
Assert.Multiple(
() => Assert.Contains("key_1:value", record.Message),
() => Assert.Contains("key_2:False", record.Message),
Expand Down Expand Up @@ -157,7 +152,9 @@ public async Task BeforeAsync_With_No_EvaluationContext_Generates_Correct_Log_Me
Context:
""",
record.Message);
record.Message,
ignoreLineEndingDifferences: true
);
}

[Fact]
Expand Down Expand Up @@ -215,7 +212,9 @@ public async Task ErrorAsync_Without_EvaluationContext_Generates_Correct_Log_Mes
DefaultValue:False
""",
record.Message);
record.Message,
ignoreLineEndingDifferences: true
);
}

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

Assert.Contains(
"""
Error during Flag Evaluation Domain:client
ProviderName:provider
FlagKey:test
DefaultValue:False
Context:
""",
record.Message);
Assert.Multiple(
() => Assert.Contains("key_1: ", record.Message),
() => Assert.Contains("key_2:True", record.Message),
Expand Down Expand Up @@ -301,7 +291,9 @@ public async Task ErrorAsync_With_No_EvaluationContext_Generates_Correct_Log_Mes
Context:
""",
record.Message);
record.Message,
ignoreLineEndingDifferences: true
);
}

[Fact]
Expand Down Expand Up @@ -358,7 +350,9 @@ public async Task AfterAsync_Without_EvaluationContext_Generates_Correct_Log_Mes
DefaultValue:False
""",
record.Message);
record.Message,
ignoreLineEndingDifferences: true
);
}

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

Assert.Contains(
"""
After Flag Evaluation Domain:client
ProviderName:provider
FlagKey:test
DefaultValue:False
Context:
""",
record.Message);

// .NET Framework uses G15 formatter on double.ToString
// .NET uses G17 formatter on double.ToString
#if NET462
Expand Down Expand Up @@ -452,7 +436,9 @@ public async Task AfterAsync_With_No_EvaluationContext_Generates_Correct_Log_Mes
Context:
""",
record.Message);
record.Message,
ignoreLineEndingDifferences: true
);
}

[Fact]
Expand Down Expand Up @@ -499,8 +485,9 @@ public async Task With_Structure_Type_In_Context_Returns_Qualified_Name_Of_Value
key_1:OpenFeature.Model.Value
""",
message
);
message,
ignoreLineEndingDifferences: true
);
}

[Fact]
Expand Down Expand Up @@ -539,8 +526,9 @@ public async Task Without_Domain_Returns_Missing()
key_1:True
""",
message
);
message,
ignoreLineEndingDifferences: true
);
}

[Fact]
Expand Down Expand Up @@ -579,8 +567,9 @@ public async Task Without_Provider_Returns_Missing()
key_1:True
""",
message
);
message,
ignoreLineEndingDifferences: true
);
}

[Fact]
Expand Down Expand Up @@ -619,8 +608,9 @@ public async Task Without_DefaultValue_Returns_Missing()
key_1:True
""",
message
);
message,
ignoreLineEndingDifferences: true
);
}

[Fact]
Expand Down Expand Up @@ -659,8 +649,9 @@ public async Task Without_EvaluationContextValue_Returns_Nothing()
key_1:
""",
message
);
message,
ignoreLineEndingDifferences: true
);
}

private static string NormalizeLogRecord(FakeLogRecord record)
Expand Down

0 comments on commit a98334e

Please sign in to comment.