-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AzureMonitorDistro] Conditionally skip failing tests (#44423)
* disable tests * Enable only DistroLogForwarderIsAdded * Enable only PublicLogForwarderIsAdded * Enable only SelfDiagnosticsIsDisabled * test conditionally skip * preprocessor
- Loading branch information
1 parent
9b963ba
commit 05dccb3
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...s/Azure.Monitor.OpenTelemetry.Exporter.Tests/CommonTestFramework/CustomXunitAttributes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Xunit | ||
{ | ||
public class CustomXunitAttributes | ||
{ | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
public class ConditionallySkipOSFactAttribute : FactAttribute | ||
{ | ||
private readonly string _platformToSkip; | ||
private readonly string _reason; | ||
|
||
public ConditionallySkipOSFactAttribute(string platformToSkip, string reason) | ||
{ | ||
_platformToSkip = platformToSkip; | ||
_reason = reason; | ||
} | ||
|
||
public override string Skip | ||
{ | ||
get => IsCurrentOS(_platformToSkip) | ||
? $"Test skipped on {_platformToSkip}. {_reason}" | ||
: base.Skip; | ||
set => base.Skip = value; | ||
} | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
public class ConditionallySkipOSTheoryAttribute : TheoryAttribute | ||
{ | ||
private readonly string _platformToSkip; | ||
private readonly string _reason; | ||
|
||
public ConditionallySkipOSTheoryAttribute(string platformToSkip, string reason) | ||
{ | ||
_platformToSkip = platformToSkip; | ||
_reason = reason; | ||
} | ||
|
||
public override string Skip | ||
{ | ||
get | ||
{ | ||
return IsCurrentOS(_platformToSkip) | ||
? $"Test skipped on {_platformToSkip}. {_reason}" | ||
: base.Skip; | ||
} | ||
set => base.Skip = value; | ||
} | ||
} | ||
|
||
private static bool IsCurrentOS(string osName) | ||
{ | ||
switch (osName.ToLowerInvariant()) | ||
{ | ||
case "windows": | ||
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); | ||
case "linux": | ||
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux); | ||
case "osx": | ||
case "macos": | ||
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); | ||
default: | ||
throw new ArgumentException($"Unsupported OS name: {osName}"); | ||
} | ||
} | ||
} | ||
} |