Skip to content

Commit 8c8e159

Browse files
committed
fix localization in unit tests
1 parent 4bab51a commit 8c8e159

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

test/OpenTelemetry.Tests/Logs/LogRecordTests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,12 @@ public void CheckStateForStructuredLogWithGeneralType(bool includeFormattedMessa
246246
{
247247
using var loggerFactory = InitializeLoggerFactory(out List<LogRecord> exportedItems, configure: o => o.IncludeFormattedMessage = includeFormattedMessage);
248248
var logger = loggerFactory.CreateLogger<LogRecordTests>();
249+
var trufflePrice = 299.99;
249250

250251
var food = new Dictionary<string, object>
251252
{
252253
["Name"] = "truffle",
253-
["Price"] = 299.99,
254+
["Price"] = trufflePrice,
254255
};
255256
logger.Food(food);
256257

@@ -276,16 +277,8 @@ public void CheckStateForStructuredLogWithGeneralType(bool includeFormattedMessa
276277
Assert.Equal("{Food}", exportedItems[0].Body);
277278
if (includeFormattedMessage)
278279
{
279-
var prevCulture = CultureInfo.CurrentCulture;
280-
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
281-
try
282-
{
283-
Assert.Equal("[Name, truffle], [Price, 299.99]", exportedItems[0].FormattedMessage);
284-
}
285-
finally
286-
{
287-
CultureInfo.CurrentCulture = prevCulture;
288-
}
280+
var priceInCurrentCulture = trufflePrice.ToString(CultureInfo.CurrentCulture);
281+
Assert.Equal($"[Name, truffle], [Price, {priceInCurrentCulture}]", exportedItems[0].FormattedMessage);
289282
}
290283
else
291284
{

test/OpenTelemetry.Tests/Trace/TracerProviderSdkTests.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Diagnostics;
5+
using System.Globalization;
56
using Microsoft.Extensions.Configuration;
67
using Microsoft.Extensions.DependencyInjection;
78
using OpenTelemetry.Resources;
@@ -1055,17 +1056,7 @@ public void SdkPopulatesSamplingParamsCorrectlyForLegacyActivityWithInProcParent
10551056
}
10561057

10571058
[Theory]
1058-
[InlineData(null, null, "ParentBased{AlwaysOnSampler}")]
1059-
[InlineData("always_on", null, "AlwaysOnSampler")]
1060-
[InlineData("always_off", null, "AlwaysOffSampler")]
1061-
[InlineData("always_OFF", null, "AlwaysOffSampler")]
1062-
[InlineData("traceidratio", "0.5", "TraceIdRatioBasedSampler{0.500000}")]
1063-
[InlineData("traceidratio", "not_a_double", "TraceIdRatioBasedSampler{1.000000}")]
1064-
[InlineData("parentbased_always_on", null, "ParentBased{AlwaysOnSampler}")]
1065-
[InlineData("parentbased_always_off", null, "ParentBased{AlwaysOffSampler}")]
1066-
[InlineData("parentbased_traceidratio", "0.111", "ParentBased{TraceIdRatioBasedSampler{0.111000}}")]
1067-
[InlineData("parentbased_traceidratio", "not_a_double", "ParentBased{TraceIdRatioBasedSampler{1.000000}}")]
1068-
[InlineData("ParentBased_TraceIdRatio", "0.000001", "ParentBased{TraceIdRatioBasedSampler{0.000001}}")]
1059+
[ClassData(typeof(SamplerSetConfigurationGenerator))]
10691060
public void TestSamplerSetFromConfiguration(string? configValue, string? argValue, string samplerDescription)
10701061
{
10711062
var configBuilder = new ConfigurationBuilder();
@@ -1383,4 +1374,26 @@ public void Dispose()
13831374
this.IsDisposed = true;
13841375
}
13851376
}
1377+
1378+
private sealed class SamplerSetConfigurationGenerator : IEnumerable<object?[]>
1379+
{
1380+
private readonly List<object?[]> data =
1381+
[
1382+
[null, null, "ParentBased{AlwaysOnSampler}"],
1383+
["always_on", null, "AlwaysOnSampler"],
1384+
["always_off", null, "AlwaysOffSampler"],
1385+
["always_OFF", null, "AlwaysOffSampler"],
1386+
["traceidratio", 0.5.ToString(CultureInfo.CurrentCulture), "TraceIdRatioBasedSampler{0.500000}"],
1387+
["traceidratio", "not_a_double", "TraceIdRatioBasedSampler{1.000000}"],
1388+
["parentbased_always_on", null, "ParentBased{AlwaysOnSampler}"],
1389+
["parentbased_always_off", null, "ParentBased{AlwaysOffSampler}"],
1390+
["parentbased_traceidratio", 0.111.ToString(CultureInfo.CurrentCulture), "ParentBased{TraceIdRatioBasedSampler{0.111000}}"],
1391+
["parentbased_traceidratio", "not_a_double", "ParentBased{TraceIdRatioBasedSampler{1.000000}}"],
1392+
["ParentBased_TraceIdRatio", 0.000001.ToString(CultureInfo.CurrentCulture), "ParentBased{TraceIdRatioBasedSampler{0.000001}}"],
1393+
];
1394+
1395+
public IEnumerator<object[]> GetEnumerator() => this.data.GetEnumerator();
1396+
1397+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => this.GetEnumerator();
1398+
}
13861399
}

0 commit comments

Comments
 (0)