Skip to content

Commit 1450463

Browse files
committed
Replace test categories for OS filter with xUnit attributes
1 parent 777f9f1 commit 1450463

File tree

17 files changed

+144
-101
lines changed

17 files changed

+144
-101
lines changed

.github/workflows/Steeltoe.All.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- os: windows-latest
3939
skipFilter: Category!=Integration
4040
- os: macos-latest
41-
skipFilter: Category!=Integration&Category!=SkipOnMacOS
41+
skipFilter: Category!=Integration
4242
runs-on: ${{ matrix.os }}
4343
continue-on-error: true
4444

@@ -74,7 +74,7 @@ jobs:
7474
# When that happens, select 'Always Allow' to grant 'dotnet' access to the certificate key in the future.
7575
# and the test run fails, but without indicating which test caused it. By setting this, the causing test fails with the next message:
7676
# Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
77-
# To prevent the causing test from failing the test run, disable it on macOS by adding [Trait("Category", "SkipOnMacOS")].
77+
# To prevent the causing test from failing the test run, disable it on macOS using SkipOnPlatformFact/Theory.
7878
shell: bash
7979
run: echo "DOTNET_GENERATE_ASPNET_CERTIFICATE=false" >> $GITHUB_ENV
8080

.github/workflows/component-configuration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
with:
2626
component: Configuration
2727
OS: ubuntu
28-
runConfigServer: true
28+
runDockerContainers: true

.github/workflows/component-management.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
with:
3232
component: Management
3333
OS: macos
34-
skipFilter: Category!=SkipOnMacOS
3534

3635
windows:
3736
uses: ./.github/workflows/component-shared-workflow.yml

.github/workflows/component-shared-workflow.yml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
skipFilter:
1313
required: false
1414
type: string
15-
runConfigServer:
15+
runDockerContainers:
1616
required: false
1717
type: boolean
1818
default: false
@@ -24,14 +24,10 @@ permissions:
2424
env:
2525
DOTNET_CLI_TELEMETRY_OPTOUT: 1
2626
DOTNET_NOLOGO: true
27-
SOLUTION_FILE: src/Steeltoe.${{ inputs.component }}.slnf
27+
SOLUTION_FILE: 'src/Steeltoe.${{ inputs.component }}.slnf'
2828
COMMON_TEST_ARGS: >-
2929
--no-build --configuration Release --collect "XPlat Code Coverage" --logger trx --results-directory ${{ github.workspace }}/dumps
3030
--settings coverlet.runsettings --blame-crash --blame-hang-timeout 3m
31-
SKIP_FILTER_NO_MEMORY_DUMPS: >-
32-
${{ inputs.skipFilter && format('--filter "{0}&Category!=MemoryDumps"', inputs.skipFilter) || '--filter "Category!=MemoryDumps"' }}
33-
SKIP_FILTER_WITH_MEMORY_DUMPS: >-
34-
${{ inputs.skipFilter && format('--filter "{0}&Category=MemoryDumps"', inputs.skipFilter) || '--filter "Category=MemoryDumps"' }}
3531
3632
jobs:
3733
build:
@@ -41,11 +37,11 @@ jobs:
4137

4238
services:
4339
eurekaServer:
44-
image: ${{ inputs.runConfigServer && 'steeltoe.azurecr.io/eureka-server' || null }}
40+
image: ${{ inputs.runDockerContainers && 'steeltoe.azurecr.io/eureka-server' || null }}
4541
ports:
4642
- 8761:8761
4743
configServer:
48-
image: ${{ inputs.runConfigServer && 'steeltoe.azurecr.io/config-server' || null }}
44+
image: ${{ inputs.runDockerContainers && 'steeltoe.azurecr.io/config-server' || null }}
4945
env:
5046
eureka.client.enabled: true
5147
eureka.client.serviceUrl.defaultZone: http://eurekaServer:8761/eureka
@@ -71,7 +67,7 @@ jobs:
7167
# When that happens, select 'Always Allow' to grant 'dotnet' access to the certificate key in the future.
7268
# and the test run fails, but without indicating which test caused it. By setting this, the causing test fails with the next message:
7369
# Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
74-
# To prevent the causing test from failing the test run, disable it on macOS by adding [Trait("Category", "SkipOnMacOS")].
70+
# To prevent the causing test from failing the test run, disable it on macOS using SkipOnPlatformFact/Theory.
7571
shell: bash
7672
run: echo "DOTNET_GENERATE_ASPNET_CERTIFICATE=false" >> $GITHUB_ENV
7773

@@ -86,33 +82,38 @@ jobs:
8682
- name: Build solution
8783
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal
8884

85+
- name: Set skip filters for tests
86+
shell: bash
87+
run: |
88+
echo SKIP_FILTER_NO_MEMORY_DUMPS="${{ inputs.skipFilter && format('{0}&Category!=MemoryDumps', inputs.skipFilter) || 'Category!=MemoryDumps' }}" >> $GITHUB_ENV
89+
echo SKIP_FILTER_WITH_MEMORY_DUMPS="${{ inputs.skipFilter && format('{0}&Category=MemoryDumps', inputs.skipFilter) || 'Category=MemoryDumps' }}" >> $GITHUB_ENV
90+
8991
- name: Test (net10.0)
90-
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net10.0 ${{ env.SKIP_FILTER_NO_MEMORY_DUMPS }} ${{ env.COMMON_TEST_ARGS }}
92+
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net10.0 --filter "${{ env.SKIP_FILTER_NO_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}
9193

9294
- name: Test (net10.0) (memory dumps)
9395
if: ${{ inputs.component == 'Management' }}
94-
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net10.0 ${{ env.SKIP_FILTER_WITH_MEMORY_DUMPS }} ${{ env.COMMON_TEST_ARGS }}
96+
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net10.0 --filter "${{ env.SKIP_FILTER_WITH_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}
9597

9698
- name: Test (net9.0)
97-
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net9.0 ${{ env.SKIP_FILTER_NO_MEMORY_DUMPS }} ${{ env.COMMON_TEST_ARGS }}
99+
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net9.0 --filter "${{ env.SKIP_FILTER_NO_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}
98100

99101
- name: Test (net9.0) (memory dumps)
100102
if: ${{ inputs.component == 'Management' }}
101-
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net9.0 ${{ env.SKIP_FILTER_WITH_MEMORY_DUMPS }} ${{ env.COMMON_TEST_ARGS }}
103+
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net9.0 --filter "${{ env.SKIP_FILTER_WITH_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}
102104

103105
- name: Test (net8.0)
104-
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net8.0 ${{ env.SKIP_FILTER_NO_MEMORY_DUMPS }} ${{ env.COMMON_TEST_ARGS }}
106+
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net8.0 --filter "${{ env.SKIP_FILTER_NO_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}
105107

106108
- name: Test (net8.0) (memory dumps)
107109
if: ${{ inputs.component == 'Management' }}
108-
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net8.0 ${{ env.SKIP_FILTER_WITH_MEMORY_DUMPS }} ${{ env.COMMON_TEST_ARGS }}
109-
110+
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net8.0 --filter "${{ env.SKIP_FILTER_WITH_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}
110111

111112
- name: Upload crash/hang dumps (on failure)
112113
if: ${{ failure() }}
113114
uses: actions/upload-artifact@v5
114115
with:
115-
name: FailedTestOutput-${{ inputs.OS }}
116+
name: FailedTestOutput-${{ inputs.OS }}-latest
116117
path: |
117118
${{ github.workspace }}/dumps/**/*.dmp
118119
${{ github.workspace }}/dumps/**/Sequence_*.xml
@@ -122,7 +123,7 @@ jobs:
122123
if: ${{ !cancelled() }}
123124
uses: dorny/test-reporter@v2
124125
with:
125-
name: ${{ inputs.OS }} test results
126+
name: ${{ inputs.OS }}-latest test results
126127
reporter: dotnet-trx
127128
path: '**/*.trx'
128129
fail-on-empty: 'true'

src/Common/test/Certificates.Test/ConfigureCertificateOptionsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Runtime.InteropServices;
56
using System.Security.Cryptography;
67
using System.Security.Cryptography.X509Certificates;
78
using System.Text.Json;
@@ -50,10 +51,9 @@ public void ConfigureCertificateOptions_BadPath_NoCertificate(string certificate
5051
options.Certificate.Should().BeNull();
5152
}
5253

53-
[Theory]
54+
[SkipOnPlatformTheory(nameof(OSPlatform.OSX))]
5455
[InlineData("")]
5556
[InlineData(CertificateName)]
56-
[Trait("Category", "SkipOnMacOS")]
5757
public void ConfigureCertificateOptions_ThrowsOnEmptyFile(string certificateName)
5858
{
5959
var appSettings = new Dictionary<string, string?>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.InteropServices;
6+
using Xunit;
7+
using Xunit.v3;
8+
9+
namespace Steeltoe.Common.TestResources;
10+
11+
/// <summary>
12+
/// Skips running the decorated test on the specified platforms.
13+
/// </summary>
14+
/// <remarks>
15+
/// A common reason for skipping tests on macOS is because the ASP.NET dev certificate is not trusted. See
16+
/// https://github.com/dotnet/aspnetcore/issues/42273.
17+
/// </remarks>
18+
[XunitTestCaseDiscoverer(typeof(FactDiscoverer))]
19+
[AttributeUsage(AttributeTargets.Method)]
20+
public sealed class SkipOnPlatformFactAttribute : FactAttribute
21+
{
22+
public SkipOnPlatformFactAttribute(params string[] platformNames)
23+
{
24+
foreach (OSPlatform platform in platformNames.Select(OSPlatform.Create))
25+
{
26+
Assert.SkipWhen(RuntimeInformation.IsOSPlatform(platform), $"Skipping test on platform {platform}.");
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.InteropServices;
6+
using Xunit;
7+
using Xunit.v3;
8+
9+
namespace Steeltoe.Common.TestResources;
10+
11+
/// <summary>
12+
/// Skips running the decorated test on the specified platforms.
13+
/// </summary>
14+
/// <remarks>
15+
/// A common reason for skipping tests on macOS is because the ASP.NET dev certificate is not trusted. See
16+
/// https://github.com/dotnet/aspnetcore/issues/42273.
17+
/// </remarks>
18+
[XunitTestCaseDiscoverer(typeof(TheoryDiscoverer))]
19+
[AttributeUsage(AttributeTargets.Method)]
20+
public sealed class SkipOnPlatformTheoryAttribute : TheoryAttribute
21+
{
22+
public SkipOnPlatformTheoryAttribute(params string[] platformNames)
23+
{
24+
foreach (OSPlatform platform in platformNames.Select(OSPlatform.Create))
25+
{
26+
Assert.SkipWhen(RuntimeInformation.IsOSPlatform(platform), $"Skipping test on platform {platform}.");
27+
}
28+
}
29+
}

src/Discovery/test/Consul.Test/Discovery/PostConfigureConsulDiscoveryOptionsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Diagnostics;
6+
using System.Runtime.InteropServices;
67
using Microsoft.Extensions.Configuration;
78
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging.Abstractions;
@@ -107,8 +108,7 @@ public async Task CanUseNetworkInterfaces()
107108
inetUtilsMock.Verify(n => n.FindFirstNonLoopbackHostInfo(), Times.Once);
108109
}
109110

110-
[Fact]
111-
[Trait("Category", "SkipOnMacOS")]
111+
[SkipOnPlatformFact(nameof(OSPlatform.OSX))]
112112
public async Task CanUseNetworkInterfacesWithoutReverseDnsOnIP()
113113
{
114114
var appSettings = new Dictionary<string, string?>

src/Discovery/test/Eureka.Test/DynamicPortAssignmentTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Runtime.InteropServices;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.Extensions.Configuration;
78
using Microsoft.Extensions.DependencyInjection;
@@ -11,8 +12,7 @@ namespace Steeltoe.Discovery.Eureka.Test;
1112

1213
public sealed class DynamicPortAssignmentTest
1314
{
14-
[Fact]
15-
[Trait("Category", "SkipOnMacOS")]
15+
[SkipOnPlatformFact(nameof(OSPlatform.OSX))]
1616
public async Task Applies_dynamically_assigned_ports_after_startup()
1717
{
1818
var appSettings = new Dictionary<string, string?>

src/Discovery/test/Eureka.Test/EurekaServiceCollectionExtensionsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Diagnostics;
6+
using System.Runtime.InteropServices;
67
using Microsoft.Extensions.Configuration;
78
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Hosting;
@@ -55,8 +56,7 @@ public async Task AddEurekaDiscoveryClient_UsesManagementOptions()
5556
options.Value.StatusPageUrlPath.Should().Be("/actuator/info");
5657
}
5758

58-
[Fact]
59-
[Trait("Category", "SkipOnMacOS")]
59+
[SkipOnPlatformFact(nameof(OSPlatform.OSX))]
6060
public async Task AddEurekaDiscoveryClient_UsesServerTimeout()
6161
{
6262
var appSettings = new Dictionary<string, string?>

0 commit comments

Comments
 (0)