diff --git a/test/IntegrationTests/AspNetTests.cs b/test/IntegrationTests/AspNetTests.cs index cda4fba769..c5b0816d73 100644 --- a/test/IntegrationTests/AspNetTests.cs +++ b/test/IntegrationTests/AspNetTests.cs @@ -50,7 +50,7 @@ public enum AppPoolMode private ITestOutputHelper Output { get; } = output; - [Theory] + [WindowsAdministratorTheory] [Trait("Category", "EndToEnd")] [Trait("Containers", "Windows")] [InlineData(AppPoolMode.Classic, Gac.UseGac)] @@ -59,8 +59,6 @@ public enum AppPoolMode [InlineData(AppPoolMode.Integrated, Gac.UseLocal)] public async Task SubmitsTraces(AppPoolMode appPoolMode, Gac useGac) { - Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges."); - // Using "*" as host requires Administrator. This is needed to make the mock collector endpoint // accessible to the Windows docker container where the test application is executed by binding // the endpoint to all network interfaces. In order to do that it is necessary to open the port @@ -86,7 +84,7 @@ public async Task SubmitsTraces(AppPoolMode appPoolMode, Gac useGac) collector.AssertExpectations(); } - [Theory] + [WindowsAdministratorTheory] [Trait("Category", "EndToEnd")] [Trait("Containers", "Windows")] [InlineData(AppPoolMode.Classic, Gac.UseGac)] @@ -95,8 +93,6 @@ public async Task SubmitsTraces(AppPoolMode appPoolMode, Gac useGac) [InlineData(AppPoolMode.Integrated, Gac.UseLocal)] public async Task SubmitTracesCapturesHttpHeaders(AppPoolMode appPoolMode, Gac useGac) { - Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges."); - // Using "*" as host requires Administrator. This is needed to make the mock collector endpoint // accessible to the Windows docker container where the test application is executed by binding // the endpoint to all network interfaces. In order to do that it is necessary to open the port @@ -161,13 +157,11 @@ public async Task SubmitTracesCapturesHttpHeaders(AppPoolMode appPoolMode, Gac u collector.AssertExpectations(); } - [Fact] + [WindowsAdministratorFact] [Trait("Category", "EndToEnd")] [Trait("Containers", "Windows")] public async Task TracesResource() { - Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges."); - // Using "*" as host requires Administrator. This is needed to make the mock collector endpoint // accessible to the Windows docker container where the test application is executed by binding // the endpoint to all network interfaces. In order to do that it is necessary to open the port @@ -197,13 +191,11 @@ public async Task TracesResource() collector.ResourceExpector.AssertExpectations(); } - [Fact] + [WindowsAdministratorFact] [Trait("Category", "EndToEnd")] [Trait("Containers", "Windows")] public async Task SubmitMetrics() { - Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges."); - // Using "*" as host requires Administrator. This is needed to make the mock collector endpoint // accessible to the Windows docker container where the test application is executed by binding // the endpoint to all network interfaces. In order to do that it is necessary to open the port diff --git a/test/IntegrationTests/DomainNeutralTests.cs b/test/IntegrationTests/DomainNeutralTests.cs index f42c2d092d..3684f6f401 100644 --- a/test/IntegrationTests/DomainNeutralTests.cs +++ b/test/IntegrationTests/DomainNeutralTests.cs @@ -14,12 +14,10 @@ public DomainNeutralTests(ITestOutputHelper output) { } - [Fact] + [WindowsAdministratorFact] [Trait("Category", "EndToEnd")] public void SubmitsTraces() { - Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges."); - using var collector = new MockSpansCollector(Output); SetExporter(collector); collector.Expect("ByteCode.Plugin.StrongNamedValidation"); diff --git a/test/IntegrationTests/OwinIISTests.cs b/test/IntegrationTests/OwinIISTests.cs index 3e7ce6ba7f..234ebf7b7f 100644 --- a/test/IntegrationTests/OwinIISTests.cs +++ b/test/IntegrationTests/OwinIISTests.cs @@ -26,13 +26,11 @@ public OwinIISTests(ITestOutputHelper output) private ITestOutputHelper Output { get; } - [Fact] + [WindowsAdministratorFact] [Trait("Category", "EndToEnd")] [Trait("Containers", "Windows")] public async Task SubmitsTraces() { - Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges."); - // Using "*" as host requires Administrator. This is needed to make the mock collector endpoint // accessible to the Windows docker container where the test application is executed by binding // the endpoint to all network interfaces. In order to do that it is necessary to open the port @@ -56,13 +54,11 @@ public async Task SubmitsTraces() collector.AssertExpectations(); } - [Fact] + [WindowsAdministratorFact] [Trait("Category", "EndToEnd")] [Trait("Containers", "Windows")] public async Task SubmitMetrics() { - Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges."); - // Using "*" as host requires Administrator. This is needed to make the mock collector endpoint // accessible to the Windows docker container where the test application is executed by binding // the endpoint to all network interfaces. In order to do that it is necessary to open the port diff --git a/test/IntegrationTests/WcfDotNetTests.cs b/test/IntegrationTests/WcfDotNetTests.cs index a5f57bc975..ed98a115ef 100644 --- a/test/IntegrationTests/WcfDotNetTests.cs +++ b/test/IntegrationTests/WcfDotNetTests.cs @@ -33,7 +33,7 @@ public static TheoryData wcfServerTestHelperFactory) { diff --git a/test/IntegrationTests/WcfIISTests.cs b/test/IntegrationTests/WcfIISTests.cs index 40d5455130..1ddd65a4b4 100644 --- a/test/IntegrationTests/WcfIISTests.cs +++ b/test/IntegrationTests/WcfIISTests.cs @@ -20,13 +20,11 @@ public WcfIISTests(ITestOutputHelper output) { } - [Fact] + [WindowsAdministratorFact] [Trait("Category", "EndToEnd")] [Trait("Containers", "Windows")] public async Task SubmitsTraces() { - Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges."); - // Using "*" as host requires Administrator. This is needed to make the mock collector endpoint // accessible to the Windows docker container where the test application is executed by binding // the endpoint to all network interfaces. In order to do that it is necessary to open the port diff --git a/test/IntegrationTests/WcfNetFrameworkTests.cs b/test/IntegrationTests/WcfNetFrameworkTests.cs index d1a85df678..e45ee5c04f 100644 --- a/test/IntegrationTests/WcfNetFrameworkTests.cs +++ b/test/IntegrationTests/WcfNetFrameworkTests.cs @@ -15,7 +15,7 @@ public WcfNetFrameworkTests(ITestOutputHelper output) { } - [Fact] + [WindowsAdministratorFact] [Trait("Category", "EndToEnd")] public async Task SubmitsTraces() { diff --git a/test/IntegrationTests/WcfTestsBase.cs b/test/IntegrationTests/WcfTestsBase.cs index 8a17fcb01b..77ff731a10 100644 --- a/test/IntegrationTests/WcfTestsBase.cs +++ b/test/IntegrationTests/WcfTestsBase.cs @@ -62,7 +62,6 @@ protected virtual void Dispose(bool disposing) protected async Task SubmitsTracesInternal(string clientPackageVersion, WcfServerTestHelperBase wcfServerTestHelperBase) { - Assert.True(!EnvironmentTools.IsWindows() || EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges."); #if NET Assert.NotNull(wcfServerTestHelperBase); #else diff --git a/test/IntegrationTests/WindowsAdministratorFactAttribute.cs b/test/IntegrationTests/WindowsAdministratorFactAttribute.cs new file mode 100644 index 0000000000..7f3d7e9a63 --- /dev/null +++ b/test/IntegrationTests/WindowsAdministratorFactAttribute.cs @@ -0,0 +1,19 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using IntegrationTests.Helpers; + +namespace IntegrationTests; + +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] +public sealed class WindowsAdministratorFactAttribute : FactAttribute +{ + public WindowsAdministratorFactAttribute() + : base() + { + Skip = GetSkipReason(); + } + + internal static string? GetSkipReason() => + !EnvironmentTools.IsWindows() || EnvironmentTools.IsWindowsAdministrator() ? null : "This test requires administrative privileges on Windows."; +} diff --git a/test/IntegrationTests/WindowsAdministratorTheoryAttribute.cs b/test/IntegrationTests/WindowsAdministratorTheoryAttribute.cs new file mode 100644 index 0000000000..898cb52a9a --- /dev/null +++ b/test/IntegrationTests/WindowsAdministratorTheoryAttribute.cs @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +namespace IntegrationTests; + +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] +public sealed class WindowsAdministratorTheoryAttribute : TheoryAttribute +{ + public WindowsAdministratorTheoryAttribute() + : base() + { + Skip = WindowsAdministratorFactAttribute.GetSkipReason(); + } +}