Repository navigation
Expand file tree
/
Copy pathMultiEngineTest.cs
More file actions
64 lines (51 loc) · 1.75 KB
/
Copy pathMultiEngineTest.cs
File metadata and controls
64 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Reflection;
using System.Runtime.InteropServices;
using GenHTTP.Api.Infrastructure;
namespace GenHTTP.Testing.Acceptance;
/// <summary>
/// When attributed on a test method, this attribute
/// injects the engines that are target to be tested
/// into the test method.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class MultiEngineTestAttribute : Attribute, ITestDataSource
{
private static readonly bool IoxideSupported = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
public IEnumerable<object[]> GetData(MethodInfo methodInfo)
{
var engine = Environment.GetEnvironmentVariable("TEST_ENGINE");
if (engine == null)
{
var engines = new List<object[]>
{
new object[] { ServerEngine.Internal },
new object[] { ServerEngine.Kestrel }
};
if (IoxideSupported)
{
engines.Add([ServerEngine.Ioxide]);
}
return engines;
}
if (Enum.TryParse(engine, out ServerEngine found))
{
if (found == ServerEngine.Ioxide && !IoxideSupported)
{
throw new InvalidOperationException("The ioxide engine is Linux-only and cannot be tested on this platform");
}
return new List<object[]>
{
new object[] { found }
};
}
throw new InvalidOperationException($"Engine '{engine}' is not supported");
}
public string GetDisplayName(MethodInfo methodInfo, object?[]? data)
{
if (data?[0] is ServerEngine engine)
{
return $"{methodInfo.Name} ({engine.ToString()})";
}
return methodInfo.Name;
}
}