Skip to content

Commit 3582401

Browse files
committed
chore: finish net10 migration
1 parent 389e90b commit 3582401

10 files changed

Lines changed: 69 additions & 104 deletions

File tree

.github/workflows/dotnetcore.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,8 @@ jobs:
3434
id: gitversion # step id used as reference for output values
3535
uses: gittools/actions/gitversion/execute@51d325634925d7d9ce0a7efc2c586c0bc2b9eee6 # v3.2.1
3636

37-
# - name: Setup SonarScanner
38-
# run: dotnet tool install --tool-path artifacts dotnet-sonarscanner
39-
40-
# - name: SonarScanner begin
41-
# run: artifacts/dotnet-sonarscanner begin /k:"Haproxy.AgentCheck" /o:"lucca" /d:sonar.login=${{ secrets.SONAR_TOKEN }} /d:sonar.host.url="https://sonarcloud.io/" /d:sonar.cs.opencover.reportsPaths="./coverage.opencover.xml"
42-
4337
- name: Test
44-
run: dotnet test --no-restore --verbosity minimal /p:CollectCoverage=true /p:CoverletOutput=../ /p:CoverletOutputFormat=opencover --logger:"console;verbosity=detailed"
45-
46-
# - name: SonarScanner end
47-
# run: artifacts/dotnet-sonarscanner end /d:sonar.login=${{ secrets.SONAR_TOKEN }}
48-
# env:
49-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
run: dotnet test --solution Haproxy.AgentCheck.sln --coverage --report-github
5039

5140
- name: Publish win-x64
5241
run: |

Directory.Packages.props

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,22 @@
44
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
55
</PropertyGroup>
66
<ItemGroup>
7+
<PackageVersion Include="GitHubActionsTestLogger" Version="3.0.1" />
8+
<PackageVersion Include="Microsoft.CodeCoverage" Version="18.0.1" />
79
<PackageVersion Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.652701" />
810
<PackageVersion Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.28" />
9-
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.11.2" />
10-
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.2" />
11-
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.11.2" />
12-
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.1" />
13-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
14-
<PackageVersion Include="coverlet.collector" Version="6.0.4">
15-
<PrivateAssets>all</PrivateAssets>
16-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17-
</PackageVersion>
18-
<PackageVersion Include="xunit" Version="2.9.3" />
19-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2">
20-
<PrivateAssets>all</PrivateAssets>
21-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22-
</PackageVersion>
23-
</ItemGroup>
24-
<ItemGroup>
11+
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.1.0" />
12+
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.14.0" />
13+
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.14.0" />
14+
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.14.0" />
2515
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
2616
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="10.0.0" />
2717
<PackageVersion Include="Microsoft.Extensions.Hosting.Systemd" Version="10.0.0" />
2818
<PackageVersion Include="Microsoft.Extensions.Hosting.WindowsServices" Version="10.0.0" />
2919
<PackageVersion Include="System.Diagnostics.PerformanceCounter" Version="10.0.0" />
20+
<PackageVersion Include="xunit.v3.mtp-v2" Version="3.2.1" />
3021
</ItemGroup>
3122
<ItemGroup>
3223
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="10.16.0.128591" />
3324
</ItemGroup>
34-
</Project>
25+
</Project>

Haproxy.AgentCheck.Tests/CountersStateTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using Lucca.Infra.Haproxy.AgentCheck.Config;
22
using Lucca.Infra.Haproxy.AgentCheck.Metrics;
33
using Microsoft.Extensions.DependencyInjection;
4-
using Microsoft.Extensions.Logging;
54
using Xunit;
6-
using Xunit.Abstractions;
75

86
namespace Lucca.Infra.Haproxy.AgentCheck.Tests;
97

Haproxy.AgentCheck.Tests/Haproxy.AgentCheck.Tests.csproj

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@
22

33
<PropertyGroup>
44
<TargetFramework>net10.0</TargetFramework>
5-
<IsTestProject>true</IsTestProject>
5+
<OutputType>Exe</OutputType>
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="GitHubActionsTestLogger" />
910
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
1011
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
12-
<PackageReference Include="coverlet.collector">
13-
<PrivateAssets>all</PrivateAssets>
14-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15-
</PackageReference>
16-
<PackageReference Include="xunit" />
17-
<PackageReference Include="xunit.runner.visualstudio">
18-
<PrivateAssets>all</PrivateAssets>
19-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20-
</PackageReference>
12+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
13+
<PackageReference Include="xunit.v3.mtp-v2" />
2114
</ItemGroup>
2215

2316
<ItemGroup>

Haproxy.AgentCheck.Tests/HttpEndpointTests.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
using Microsoft.Extensions.Configuration;
77
using Microsoft.Extensions.DependencyInjection;
88
using Microsoft.Extensions.Logging;
9-
using Lucca.Infra.Haproxy.AgentCheck.Metrics;
109
using Xunit;
11-
using Xunit.Abstractions;
1210

1311
namespace Lucca.Infra.Haproxy.AgentCheck.Tests;
1412

@@ -20,12 +18,12 @@ public async Task GetRoot_ReturnsJsonWithStateInfo()
2018
await using var factory = CreateFactory();
2119
var client = factory.CreateClient();
2220

23-
var response = await client.GetAsync("/");
21+
var response = await client.GetAsync("/", TestContext.Current.CancellationToken);
2422

2523
response.EnsureSuccessStatusCode();
2624
Assert.Equal("application/json", response.Content.Headers.ContentType?.MediaType);
2725

28-
var content = await response.Content.ReadAsStringAsync();
26+
var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
2927
Assert.Contains("isUp", content, StringComparison.OrdinalIgnoreCase);
3028
Assert.Contains("weight", content, StringComparison.OrdinalIgnoreCase);
3129
}
@@ -36,7 +34,7 @@ public async Task MaintenanceEndpoint_WithoutAuth_ReturnsUnauthorized()
3634
await using var factory = CreateFactory();
3735
var client = factory.CreateClient();
3836

39-
var response = await client.PostAsync("/admin/maintenance", null);
37+
var response = await client.PostAsync("/admin/maintenance", null, TestContext.Current.CancellationToken);
4038

4139
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
4240
}
@@ -47,7 +45,7 @@ public async Task ReadyEndpoint_WithoutAuth_ReturnsUnauthorized()
4745
await using var factory = CreateFactory();
4846
var client = factory.CreateClient();
4947

50-
var response = await client.PostAsync("/admin/ready", null);
48+
var response = await client.PostAsync("/admin/ready", null, TestContext.Current.CancellationToken);
5149

5250
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
5351
}
@@ -59,7 +57,7 @@ public async Task MaintenanceEndpoint_WithBasicAuth_SetsMaintenanceMode()
5957
var client = factory.CreateClient();
6058
client.DefaultRequestHeaders.Authorization = CreateBasicAuthHeader("admin", "admin");
6159

62-
var response = await client.PostAsync("/admin/maintenance", null);
60+
var response = await client.PostAsync("/admin/maintenance", null, TestContext.Current.CancellationToken);
6361

6462
response.EnsureSuccessStatusCode();
6563

@@ -79,7 +77,7 @@ public async Task ReadyEndpoint_WithBasicAuth_ClearsMaintenanceMode()
7977
var maintenanceStatus = factory.Services.GetRequiredService<MaintenanceStatus>();
8078
maintenanceStatus.IsMaintenance = true;
8179

82-
var response = await client.PostAsync("/admin/ready", null);
80+
var response = await client.PostAsync("/admin/ready", null, TestContext.Current.CancellationToken);
8381

8482
response.EnsureSuccessStatusCode();
8583
Assert.False(maintenanceStatus.IsMaintenance);
@@ -92,7 +90,7 @@ public async Task MaintenanceEndpoint_WithWrongCredentials_ReturnsUnauthorized()
9290
var client = factory.CreateClient();
9391
client.DefaultRequestHeaders.Authorization = CreateBasicAuthHeader("wrong", "credentials");
9492

95-
var response = await client.PostAsync("/admin/maintenance", null);
93+
var response = await client.PostAsync("/admin/maintenance", null, TestContext.Current.CancellationToken);
9694

9795
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
9896
}

Haproxy.AgentCheck.Tests/IntegrationTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.AspNetCore.Mvc.Testing;
55
using Microsoft.Extensions.Logging;
66
using Xunit;
7-
using Xunit.Abstractions;
87

98
namespace Lucca.Infra.Haproxy.AgentCheck.Tests;
109
#pragma warning disable S1144
@@ -24,7 +23,7 @@ public async Task StartAndGatherTcp()
2423
});
2524
});
2625
var client = f.CreateClient();
27-
var s = await client.GetStringAsync("");
26+
var s = await client.GetStringAsync("", TestContext.Current.CancellationToken);
2827
Assert.Equal("CPU : 0%\nIIS Requests : 0", s);
2928
Assert.True(true);
3029
}

Haproxy.AgentCheck.Tests/StateTests.cs

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using Lucca.Infra.Haproxy.AgentCheck.Config;
1+
using Lucca.Infra.Haproxy.AgentCheck.Config;
22
using Lucca.Infra.Haproxy.AgentCheck.Metrics;
33
using Microsoft.Extensions.DependencyInjection;
44
using Xunit;
5-
using Xunit.Abstractions;
65

76
namespace Lucca.Infra.Haproxy.AgentCheck.Tests;
87

@@ -25,7 +24,7 @@ public void Check_linear_weight_rule(WeightRuleData data)
2524
{
2625
Name = "CPU",
2726
Source = RuleSource.System,
28-
Weight = new()
27+
Weight = new WeightRule
2928
{
3029
SystemResponse = SystemResponse.Linear,
3130
MinValue = data.MinValue,
@@ -49,7 +48,7 @@ public void Check_firstOrder_weight_rule(WeightRuleData data)
4948
{
5049
Name = "CPU",
5150
Source = RuleSource.System,
52-
Weight = new()
51+
Weight = new WeightRule
5352
{
5453
SystemResponse = SystemResponse.FirstOrder,
5554
MinValue = data.MinValue,
@@ -68,20 +67,20 @@ public void Check_firstOrder_weight_rule(WeightRuleData data)
6867
public void Check_that_the_lowest_weight_is_used()
6968
{
7069
var serviceProvider = CreateServiceProvider(
71-
new()
70+
new RuleConfig
7271
{
7372
Name = "CPU",
7473
Source = RuleSource.System,
75-
Weight = new()
74+
Weight = new WeightRule
7675
{
7776
SystemResponse = SystemResponse.Linear
7877
}
7978
},
80-
new()
79+
new RuleConfig
8180
{
8281
Name = "IisRequests",
8382
Source = RuleSource.System,
84-
Weight = new()
83+
Weight = new WeightRule
8584
{
8685
SystemResponse = SystemResponse.Linear
8786
}
@@ -100,7 +99,7 @@ public void Check_that_given_metric_below_threshold_state_is_up()
10099
{
101100
Name = "CPU",
102101
Source = RuleSource.System,
103-
Failure = new()
102+
Failure = new FailureRule
104103
{
105104
EnterThreshold = 60,
106105
LeaveThreshold = 40
@@ -120,7 +119,7 @@ public void Check_that_given_metric_above_threshold_state_is_down()
120119
{
121120
Name = "CPU",
122121
Source = RuleSource.System,
123-
Failure = new()
122+
Failure = new FailureRule
124123
{
125124
EnterThreshold = 60,
126125
LeaveThreshold = 40
@@ -136,21 +135,21 @@ public void Check_that_given_metric_above_threshold_state_is_down()
136135
public void Check_that_given_one_metric_above_threshold_state_is_down()
137136
{
138137
var serviceProvider = CreateServiceProvider(
139-
new()
138+
new RuleConfig
140139
{
141140
Name = "CPU",
142141
Source = RuleSource.System,
143-
Failure = new()
142+
Failure = new FailureRule
144143
{
145144
EnterThreshold = 60,
146145
LeaveThreshold = 40
147146
}
148147
},
149-
new()
148+
new RuleConfig
150149
{
151150
Name = "IisRequests",
152151
Source = RuleSource.System,
153-
Failure = new()
152+
Failure = new FailureRule
154153
{
155154
EnterThreshold = 10,
156155
LeaveThreshold = 10
@@ -171,7 +170,7 @@ public void Check_that_given_broken_circuit_breaker_with_metric_between_threshol
171170
{
172171
Name = "CPU",
173172
Source = RuleSource.System,
174-
Failure = new()
173+
Failure = new FailureRule
175174
{
176175
EnterThreshold = 60,
177176
LeaveThreshold = 40
@@ -192,7 +191,7 @@ public void Check_that_given_broken_circuit_breaker_with_metric_below_threshold_
192191
{
193192
Name = "CPU",
194193
Source = RuleSource.System,
195-
Failure = new()
194+
Failure = new FailureRule
196195
{
197196
EnterThreshold = 60,
198197
LeaveThreshold = 40
@@ -213,7 +212,7 @@ public void Check_that_given_broken_circuit_breaker_with_metric_below_threshold_
213212
{
214213
Name = "CPU",
215214
Source = RuleSource.System,
216-
Failure = new()
215+
Failure = new FailureRule
217216
{
218217
EnterThreshold = 60,
219218
LeaveThreshold = 40,
@@ -235,7 +234,7 @@ public void Check_that_given_broken_circuit_breaker_with_metric_below_threshold_
235234
{
236235
Name = "CPU",
237236
Source = RuleSource.System,
238-
Failure = new()
237+
Failure = new FailureRule
239238
{
240239
EnterThreshold = 60,
241240
LeaveThreshold = 40,
@@ -259,7 +258,7 @@ public void Check_that_given_fixed_circuit_breaker_with_metric_not_below_thresho
259258
{
260259
Name = "CPU",
261260
Source = RuleSource.System,
262-
Failure = new()
261+
Failure = new FailureRule
263262
{
264263
EnterThreshold = 60,
265264
LeaveThreshold = 40,
@@ -277,42 +276,41 @@ public void Check_that_given_fixed_circuit_breaker_with_metric_not_below_thresho
277276

278277
public static TheoryData<WeightRuleData> GetLinearResponseTestData()
279278
{
280-
return new TheoryData<WeightRuleData>
281-
{
282-
new(0, 100, 0, 100, 0, 100),
283-
new(50, 50, 0, 100, 0, 100),
284-
new(100, 0, 0, 100, 0, 100),
279+
return new TheoryData<WeightRuleData>(
280+
new WeightRuleData(0, 100, 0, 100, 0, 100),
281+
new WeightRuleData(50, 50, 0, 100, 0, 100),
282+
new WeightRuleData(100, 0, 0, 100, 0, 100),
285283

286-
new(0, 80, 0, 100, 10, 80),
287-
new(50, 45, 0, 100, 10, 80),
288-
new(100, 10, 0, 100, 10, 80),
284+
new WeightRuleData(0, 80, 0, 100, 10, 80),
285+
new WeightRuleData(50, 45, 0, 100, 10, 80),
286+
new WeightRuleData(100, 10, 0, 100, 10, 80),
289287

290-
new(0, 100, 10, 80, 0, 100),
291-
new(10, 100, 10, 80, 0, 100),
292-
new(50, 42.85, 10, 80, 0, 100),
293-
new(80, 0, 10, 80, 0, 100),
294-
new(100, 0, 10, 80, 0, 100)
295-
};
288+
new WeightRuleData(0, 100, 10, 80, 0, 100),
289+
new WeightRuleData(10, 100, 10, 80, 0, 100),
290+
new WeightRuleData(50, 42.85, 10, 80, 0, 100),
291+
new WeightRuleData(80, 0, 10, 80, 0, 100),
292+
new WeightRuleData(100, 0, 10, 80, 0, 100)
293+
);
296294
}
297295

298296
public static TheoryData<WeightRuleData> GetFirstOrderResponseTestData()
299297
{
300-
return new TheoryData<WeightRuleData>
301-
{
302-
new(0, 100, 0, 100, 0, 100),
303-
new(50, 9.05, 0, 100, 0, 100),
304-
new(100, 0, 0, 100, 0, 100),
298+
return new TheoryData<WeightRuleData>(
299+
300+
new WeightRuleData(0, 100, 0, 100, 0, 100),
301+
new WeightRuleData(50, 9.05, 0, 100, 0, 100),
302+
new WeightRuleData(100, 0, 0, 100, 0, 100),
305303

306-
new(0, 80, 0, 100, 10, 80),
307-
new(50, 17.42, 0, 100, 10, 80),
308-
new(100, 10, 0, 100, 10, 80),
304+
new WeightRuleData( 0, 80, 0, 100, 10, 80),
305+
new WeightRuleData(50, 17.42, 0, 100, 10, 80),
306+
new WeightRuleData(100, 10, 0, 100, 10, 80),
309307

310-
new(0, 100, 10, 80, 0, 100),
311-
new(10, 100, 10, 80, 0, 100),
312-
new(45, 9.05, 10, 80, 0, 100),
313-
new(80, 0, 10, 80, 0, 100),
314-
new(100, 0, 10, 80, 0, 100)
315-
};
308+
new WeightRuleData(0, 100, 10, 80, 0, 100),
309+
new WeightRuleData(10, 100, 10, 80, 0, 100),
310+
new WeightRuleData(45, 9.05, 10, 80, 0, 100),
311+
new WeightRuleData(80, 0, 10, 80, 0, 100),
312+
new WeightRuleData(100, 0, 10, 80, 0, 100)
313+
);
316314
}
317315

318316
private IServiceProvider CreateServiceProvider(params RuleConfig[] rules)

0 commit comments

Comments
 (0)