Skip to content

Commit 60e8017

Browse files
[Infra] Fix broken test
Fix test broken by change in behaviour in .NET 10.
1 parent 8e2648b commit 60e8017

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/README.net10.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@
455455
"IdealHttpRoute": "/Index",
456456
"ActivityDisplayName": "GET",
457457
"ActivityHttpRoute": "",
458-
"MetricHttpRoute": "",
458+
"MetricHttpRoute": "/",
459459
"RouteInfo": {
460460
"HttpMethod": "GET",
461461
"Path": "/",

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestCases.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ public static IEnumerable<object[]> GetTestCases()
2727
private static List<object[]> GetArgumentsFromTestCaseObject(IEnumerable<TestCase> input)
2828
{
2929
var result = new List<object[]>();
30+
var dotnetVersion = Environment.Version.Major;
3031

3132
foreach (var testCase in input)
3233
{
33-
if (testCase.MinimumDotnetVersion.HasValue && Environment.Version.Major < testCase.MinimumDotnetVersion.Value)
34+
if ((testCase.MinimumDotnetVersion.HasValue && dotnetVersion < testCase.MinimumDotnetVersion.Value) ||
35+
(testCase.MaximumDotnetVersion.HasValue && dotnetVersion > testCase.MaximumDotnetVersion.Value))
3436
{
3537
continue;
3638
}

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestCases.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,24 @@
128128
{
129129
"name": "Root path",
130130
"testApplicationScenario": "RazorPages",
131+
"maximumDotnetVersion": 9,
131132
"httpMethod": "GET",
132133
"path": "/",
133134
"expectedStatusCode": 200,
134135
"currentHttpRoute": "",
135136
"expectedHttpRoute": "/Index"
136137
},
138+
{
139+
"name": "Root path",
140+
"testApplicationScenario": "RazorPages",
141+
"minimumDotnetVersion": 10,
142+
"httpMethod": "GET",
143+
"path": "/",
144+
"expectedStatusCode": 200,
145+
"currentHttpRoute": "",
146+
"expectedHttpRoute": "/Index",
147+
"expectedMetricRoute": "/"
148+
},
137149
{
138150
"name": "Index page",
139151
"testApplicationScenario": "RazorPages",

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ public async Task TestHttpRoute(TestCase testCase)
7474
Assert.Equal(testCase.HttpMethod, activityHttpMethod);
7575
Assert.Equal(testCase.HttpMethod, metricHttpMethod);
7676

77-
// TODO: The CurrentHttpRoute property will go away. It They only serve to capture status quo.
77+
// TODO: The CurrentHttpRoute property will go away. They only serve to capture status quo.
7878
// If CurrentHttpRoute is null, then that means we already conform to the correct behavior.
7979
var expectedHttpRoute = testCase.CurrentHttpRoute ?? testCase.ExpectedHttpRoute;
8080
Assert.Equal(expectedHttpRoute, activityHttpRoute);
81-
Assert.Equal(expectedHttpRoute, metricHttpRoute);
81+
82+
var expectedMetricRoute = testCase.ExpectedMetricRoute ?? expectedHttpRoute;
83+
Assert.Equal(expectedMetricRoute, metricHttpRoute);
8284

8385
// Activity.DisplayName should be a combination of http.method + http.route attributes, see:
8486
// https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#name

test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestCase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class TestCase
1111

1212
public int? MinimumDotnetVersion { get; set; }
1313

14+
public int? MaximumDotnetVersion { get; set; }
15+
1416
public TestApplicationScenario TestApplicationScenario { get; set; }
1517

1618
public string? HttpMethod { get; set; }
@@ -23,6 +25,8 @@ public class TestCase
2325

2426
public string? CurrentHttpRoute { get; set; }
2527

28+
public string? ExpectedMetricRoute { get; set; }
29+
2630
public override string ToString()
2731
{
2832
// This is used by Visual Studio's test runner to identify the test case.

0 commit comments

Comments
 (0)