2020-04-28 18:34:25 -04:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace k8s.Tests
|
|
|
|
|
{
|
|
|
|
|
public class OperatingSystemDependentFactAttribute : FactAttribute
|
|
|
|
|
{
|
2020-11-22 14:52:09 -08:00
|
|
|
public OperatingSystems Include { get; set; } = OperatingSystems.Linux | OperatingSystems.Windows | OperatingSystems.OSX;
|
|
|
|
|
public OperatingSystems Exclude { get; set; }
|
2020-04-28 18:34:25 -04:00
|
|
|
|
|
|
|
|
public override string Skip
|
|
|
|
|
{
|
|
|
|
|
get => IsOS(Include) && !IsOS(Exclude) ? null : "Not compatible with current OS";
|
|
|
|
|
set { }
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 14:52:09 -08:00
|
|
|
private bool IsOS(OperatingSystems operatingSystems)
|
2020-04-28 18:34:25 -04:00
|
|
|
{
|
2020-11-22 14:52:09 -08:00
|
|
|
if (operatingSystems.HasFlag(OperatingSystems.Linux) && RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
2020-04-28 18:34:25 -04:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 14:52:09 -08:00
|
|
|
if (operatingSystems.HasFlag(OperatingSystems.Windows) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
2020-04-28 18:34:25 -04:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 14:52:09 -08:00
|
|
|
if (operatingSystems.HasFlag(OperatingSystems.OSX) && RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
2020-04-28 18:34:25 -04:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|