Skip to content

Commit 2fe876e

Browse files
authored
Merge pull request #272 from DuendeSoftware/beh/im-tests-on-net48
Run IdentityModel Tests on Windows
2 parents 1144ce2 + d19ba10 commit 2fe876e

File tree

4 files changed

+121
-24
lines changed

4 files changed

+121
-24
lines changed

.github/workflow-gen/Program.cs

Lines changed: 91 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@
99
new("ignore-this",
1010
["IgnoreThis"],
1111
["IgnoreThis.Tests"],
12-
"it"),
12+
"it",
13+
[GitHubHostedRunners.UbuntuLatest]),
1314

1415
new("access-token-management",
1516
["AccessTokenManagement", "AccessTokenManagement.OpenIdConnect"],
1617
["AccessTokenManagement.Tests"],
17-
"atm"),
18+
"atm",
19+
[GitHubHostedRunners.UbuntuLatest]),
1820

1921
new("identity-model",
2022
["IdentityModel"],
2123
["IdentityModel.Tests"],
22-
"im"),
24+
"im",
25+
[GitHubHostedRunners.UbuntuLatest, GitHubHostedRunners.WindowsLatest]),
2326

2427
new("identity-model-oidc-client",
2528
["IdentityModel.OidcClient", "IdentityModel.OidcClient.Extensions"],
2629
["IdentityModel.OidcClient.Tests"],
27-
"imoc"),
30+
"imoc",
31+
[GitHubHostedRunners.UbuntuLatest]),
2832

2933
new("introspection",
3034
["AspNetCore.Authentication.OAuth2Introspection"],
3135
["AspNetCore.Authentication.OAuth2Introspection.Tests"],
32-
"intro"),
36+
"intro",
37+
[GitHubHostedRunners.UbuntuLatest]),
3338
];
3439

3540
foreach (var component in components)
@@ -68,8 +73,22 @@ void GenerateCiWorkflow(Component component)
6873

6974
var job = workflow
7075
.Job("build")
71-
.Name("Build")
72-
.RunsOn(GitHubHostedRunners.UbuntuLatest)
76+
.Name("Build");
77+
78+
if (component.RunsOn.Length == 1)
79+
{
80+
job.RunsOn(component.RunsOn[0]);
81+
}
82+
else
83+
{
84+
job.Strategy()
85+
.Matrix(("os", component.RunsOn))
86+
.FailFast(false)
87+
.Job
88+
.RunsOn("${{ matrix.os }}");
89+
}
90+
91+
job = job
7392
.Defaults().Run("bash", component.Name)
7493
.Job;
7594

@@ -90,12 +109,23 @@ void GenerateCiWorkflow(Component component)
90109

91110
job.StepVerifyFormatting();
92111

112+
var runsOnIncludesWindows = component.RunsOn.Contains(GitHubHostedRunners.WindowsLatest);
93113
foreach (var testProject in component.Tests)
94114
{
95-
job.StepTest(component.Name, testProject);
115+
job.StepTest(component.Name, testProject, runsOnIncludesWindows);
116+
117+
if (runsOnIncludesWindows)
118+
{
119+
job.StepTest(component.Name, testProject, false, "net481");
120+
}
96121
}
97122

98-
job.StepUploadTestResultsAsArtifact(component);
123+
job.StepUploadTestResultsAsArtifact(component, runsOnIncludesWindows);
124+
125+
if (runsOnIncludesWindows)
126+
{
127+
job.StepUploadTestResultsAsArtifact(component, false, "net481");
128+
}
99129

100130
job.StepToolRestore();
101131

@@ -235,6 +265,11 @@ void GenerateUploadTestResultsWorkflow()
235265
foreach (var testProject in component.Tests)
236266
{
237267
job.StepGenerateReportFromTestArtifact(component, testProject);
268+
269+
if (component.RunsOn.Contains(GitHubHostedRunners.WindowsLatest))
270+
{
271+
job.StepGenerateReportFromTestArtifact(component, $"{testProject}-net481", "test-results-net481");
272+
}
238273
}
239274
}
240275

@@ -249,7 +284,7 @@ void WriteWorkflow(Workflow workflow, string fileName)
249284
Console.WriteLine($"Wrote workflow to {filePath}");
250285
}
251286

252-
record Component(string Name, string[] Projects, string[] Tests, string TagPrefix)
287+
record Component(string Name, string[] Projects, string[] Tests, string TagPrefix, string[] RunsOn)
253288
{
254289
public string CiWorkflowName => $"{Name}/ci";
255290
public string ReleaseWorkflowName => $"{Name}/release";
@@ -270,39 +305,74 @@ public static void StepSetupDotNet(this Job job)
270305
public static Step IfRefMain(this Step step)
271306
=> step.If("github.ref == 'refs/heads/main'");
272307

273-
public static void StepTest(this Job job, string componentName, string testProject)
308+
internal static Step IfWindows(this Step step)
309+
=> step.If("matrix.os == 'windows-latest'");
310+
311+
internal static Step IfNotWindows(this Step step)
312+
=> step.If("matrix.os != 'windows-latest'");
313+
314+
public static void StepTest(this Job job, string componentName, string testProject, bool excludeOnWindows, string? framework = null)
274315
{
316+
var testProjectFullName = $"{testProject}{(framework == null ? string.Empty : $"-{framework}")}";
275317
var path = $"test/{testProject}";
276-
var logFileName = $"{testProject}.trx";
318+
var logFileName = $"{testProjectFullName}.trx";
277319
var flags = $"--logger \"console;verbosity=normal\" " +
278320
$"--logger \"trx;LogFileName={logFileName}\" " +
279321
$"--collect:\"XPlat Code Coverage\"";
280-
job.Step()
281-
.Name($"Test - {testProject}")
322+
323+
if (framework != null)
324+
{
325+
flags += $" --framework {framework}";
326+
}
327+
328+
var testStep = job.Step()
329+
.Name($"Test - {testProjectFullName}")
282330
.Run($"dotnet test -c Release {path} {flags}");
283331

332+
if (excludeOnWindows)
333+
{
334+
testStep.IfNotWindows();
335+
}
336+
337+
if (framework == "net481")
338+
{
339+
testStep.IfWindows();
340+
}
284341
}
285342

286-
internal static void StepUploadTestResultsAsArtifact(this Job job, Component component)
287-
=> job.Step()
288-
.Name($"Test report")
343+
internal static void StepUploadTestResultsAsArtifact(this Job job, Component component, bool excludeOnWindows, string? framework = null)
344+
{
345+
var nameSuffix = framework == null ? string.Empty : $"-{framework}";
346+
var uploadStep = job.Step()
347+
.Name($"Test report{nameSuffix}")
289348
.If("success() || failure()")
290349
.Uses("actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882") // 4.4.3
291350
.With(
292-
("name", "test-results"),
351+
("name", $"test-results{nameSuffix}"),
293352
("path", string.Join(Environment.NewLine, component.Tests
294-
.Select(testProject => $"{component.Name}/test/{testProject}/TestResults/{testProject}.trx"))),
353+
.Select(testProject => $"{component.Name}/test/{testProject}/TestResults/{testProject}{nameSuffix}.trx"))),
295354
("retention-days", "5"));
296355

297-
internal static void StepGenerateReportFromTestArtifact(this Job job, Component component, string testProject)
356+
if (excludeOnWindows)
357+
{
358+
uploadStep.IfNotWindows();
359+
}
360+
361+
if (framework == "net481")
362+
{
363+
uploadStep.IfWindows();
364+
}
365+
}
366+
367+
internal static void StepGenerateReportFromTestArtifact(this Job job, Component component, string testProject, string? artifactName = "test-results")
298368
{
299369
var path = $"test/{testProject}";
300370
job.Step()
301371
.Name($"Test report - {component.Name} - {testProject}")
302372
.Uses("dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5") // v1.9.1
303373
.If($"github.event.workflow.name == '{component.CiWorkflowName}'")
304374
.With(
305-
("artifact", "test-results"),
375+
("artifact", $"{artifactName}"),
306376
("name", $"Test Report - {testProject}"),
307377
("path", $"{testProject}.trx"),
308378
("reporter", "dotnet-trx"),

.github/workflows/generate-test-reports.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ jobs:
5151
reporter: dotnet-trx
5252
fail-on-error: true
5353
fail-on-empty: true
54+
- name: Test report - identity-model - IdentityModel.Tests-net481
55+
if: github.event.workflow.name == 'identity-model/ci'
56+
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
57+
with:
58+
artifact: test-results-net481
59+
name: Test Report - IdentityModel.Tests-net481
60+
path: IdentityModel.Tests-net481.trx
61+
reporter: dotnet-trx
62+
fail-on-error: true
63+
fail-on-empty: true
5464
- name: Test report - identity-model-oidc-client - IdentityModel.OidcClient.Tests
5565
if: github.event.workflow.name == 'identity-model-oidc-client/ci'
5666
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5

.github/workflows/identity-model-ci.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ env:
2727
jobs:
2828
build:
2929
name: Build
30-
runs-on: ubuntu-latest
30+
runs-on: ${{ matrix.os }}
3131
permissions:
3232
actions: read
3333
checks: write
@@ -37,6 +37,12 @@ jobs:
3737
run:
3838
shell: bash
3939
working-directory: identity-model
40+
strategy:
41+
matrix:
42+
os:
43+
- ubuntu-latest
44+
- windows-latest
45+
fail-fast: false
4046
timeout-minutes: 15
4147
steps:
4248
- name: Checkout
@@ -55,14 +61,25 @@ jobs:
5561
- name: Verify Formatting
5662
run: dotnet format ../ --verify-no-changes --no-restore
5763
- name: Test - IdentityModel.Tests
64+
if: matrix.os != 'windows-latest'
5865
run: dotnet test -c Release test/IdentityModel.Tests --logger "console;verbosity=normal" --logger "trx;LogFileName=IdentityModel.Tests.trx" --collect:"XPlat Code Coverage"
66+
- name: Test - IdentityModel.Tests-net481
67+
if: matrix.os == 'windows-latest'
68+
run: dotnet test -c Release test/IdentityModel.Tests --logger "console;verbosity=normal" --logger "trx;LogFileName=IdentityModel.Tests-net481.trx" --collect:"XPlat Code Coverage" --framework net481
5969
- name: Test report
60-
if: success() || failure()
70+
if: matrix.os != 'windows-latest'
6171
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
6272
with:
6373
name: test-results
6474
path: identity-model/test/IdentityModel.Tests/TestResults/IdentityModel.Tests.trx
6575
retention-days: 5
76+
- name: Test report-net481
77+
if: matrix.os == 'windows-latest'
78+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
79+
with:
80+
name: test-results-net481
81+
path: identity-model/test/IdentityModel.Tests/TestResults/IdentityModel.Tests-net481.trx
82+
retention-days: 5
6683
- name: Tool restore
6784
run: dotnet tool restore
6885
- name: Pack IdentityModel

identity-model/test/IdentityModel.Tests/HttpClientExtensions/DynamicClientRegistrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public async Task Extensions_should_be_serializable()
180180
response.ShouldNotBeNull();
181181

182182
//ensure the extension made it into the request
183-
var requestContent = await handler.Request?.Content?.ReadAsStringAsync()!;
183+
var requestContent = handler.Body;
184184
var requestContentJson = JsonSerializer.Deserialize<JsonElement>(requestContent);
185185
requestContentJson.GetProperty("custom_field").GetString().ShouldBe("data");
186186
}

0 commit comments

Comments
 (0)