From 42e857edcd57ec72a2d5487c747a01baff3309e0 Mon Sep 17 00:00:00 2001 From: Lucas Pimentel Date: Tue, 18 Jun 2024 15:04:10 -0400 Subject: [PATCH] use same logic to convert JToken to string --- .../DynamicConfigurationTests.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/DynamicConfigurationTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/DynamicConfigurationTests.cs index 5dbc4d71e5cb..c46c03371ff9 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/DynamicConfigurationTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/DynamicConfigurationTests.cs @@ -209,11 +209,25 @@ static string FlattenJsonArray(JToken json) return string.Empty; } + static string JTokenToString(JToken token) + { + return token switch + { + null => null, + _ => token.Type switch + { + JTokenType.Null or JTokenType.None or JTokenType.Undefined => null, + JTokenType.String => token.Value(), + _ => token.ToString(Formatting.None) // serialize back into json + } + }; + } + // json["runtime_metrics_enabled"]?.Value().Should().Be(expectedConfig.RuntimeMetricsEnabled); // json["debug"]?.Value().Should().Be(expectedConfig.DebugLogsEnabled); json["log_injection_enabled"]?.Value().Should().Be(expectedConfig.LogInjectionEnabled); json["sample_rate"]?.Value().Should().Be(expectedConfig.TraceSampleRate); - json["remote_sampling_rules"]?.ToString(Formatting.None).Should().Be(expectedConfig.TraceSamplingRules); + JTokenToString(json["remote_sampling_rules"]).Should().Be(expectedConfig.TraceSamplingRules); // json["span_sampling_rules"]?.Value().Should().Be(expectedConfig.SpanSamplingRules); // json["data_streams_enabled"]?.Value().Should().Be(expectedConfig.DataStreamsEnabled); FlattenJsonArray(json["header_tags"]).Should().Be(expectedConfig.TraceHeaderTags ?? string.Empty); @@ -255,7 +269,7 @@ private void AssertConfigurationChanged(ConcurrentStack events, Config c // (ConfigurationKeys.DebugEnabled, config.DebugLogsEnabled), (ConfigurationKeys.LogsInjectionEnabled, config.LogInjectionEnabled), (ConfigurationKeys.GlobalSamplingRate, config.TraceSampleRate), - (ConfigurationKeys.CustomSamplingRules, config.TraceSamplingRules == null ? null : JToken.Parse(config.TraceSamplingRules).ToString()), + (ConfigurationKeys.CustomSamplingRules, config.TraceSamplingRules == null ? null : JToken.Parse(config.TraceSamplingRules).ToString(Formatting.None)), // (ConfigurationKeys.SpanSamplingRules, config.SpanSamplingRules), // (ConfigurationKeys.DataStreamsMonitoring.Enabled, config.DataStreamsEnabled), (ConfigurationKeys.HeaderTags, config.TraceHeaderTags == null ? null : JToken.Parse(config.TraceHeaderTags).ToString()),