Skip to content

Commit

Permalink
Add unit tests to cover new LoggingHook
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Julian <[email protected]>
  • Loading branch information
kylejuliandev committed Jan 9, 2025
1 parent 6d72e66 commit ea2b393
Show file tree
Hide file tree
Showing 4 changed files with 514 additions and 4 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageVersion Include="coverlet.msbuild" Version="6.0.3" />
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="SpecFlow" Version="3.9.74" />
Expand Down
11 changes: 8 additions & 3 deletions src/OpenFeature/Hooks/LoggingHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public sealed partial class LoggingHook : Hook
/// </summary>
public LoggingHook(ILogger logger, bool includeContext = false)
{
if (logger == null) throw new ArgumentNullException(nameof(logger));

this._logger = logger;
this._includeContext = includeContext;
}
Expand Down Expand Up @@ -78,19 +80,16 @@ public override ValueTask AfterAsync<T>(HookContext<T> context, FlagEvaluationDe
}

[LoggerMessage(
EventId = 0,
Level = LogLevel.Debug,
Message = "Before Flag Evaluation {Content}")]
partial void HookBeforeStageExecuted(LoggingHookContent content);

[LoggerMessage(
EventId = 0,
Level = LogLevel.Error,
Message = "Error during Flag Evaluation {Content}")]
partial void HookErrorStageExecuted(LoggingHookContent content);

[LoggerMessage(
EventId = 0,
Level = LogLevel.Debug,
Message = "After Flag Evaluation {Content}")]
partial void HookAfterStageExecuted(LoggingHookContent content);
Expand Down Expand Up @@ -166,6 +165,12 @@ public override string ToString()
if (value.IsBoolean)
return value.AsBoolean.ToString();

if (value.IsNumber)
{
if (value.AsDouble != null) return value.AsDouble.ToString();
if (value.AsInteger != null) return value.AsInteger.ToString();
}

Check warning on line 172 in src/OpenFeature/Hooks/LoggingHook.cs

View check run for this annotation

Codecov / codecov/patch

src/OpenFeature/Hooks/LoggingHook.cs#L172

Added line #L172 was not covered by tests

if (value.IsDateTime)
return value.AsDateTime?.ToString("O");

Expand Down
Loading

0 comments on commit ea2b393

Please sign in to comment.