consolidate the tests locations
This commit is contained in:
15
src/__Tests/shared/OpenSslAutoInit.cs
Normal file
15
src/__Tests/shared/OpenSslAutoInit.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StellaOps.Testing;
|
||||
|
||||
/// <summary>
|
||||
/// Automatically ensures OpenSSL 1.1 shim is visible for tests that require legacy OpenSSL.
|
||||
/// </summary>
|
||||
internal static class OpenSslAutoInit
|
||||
{
|
||||
[ModuleInitializer]
|
||||
public static void Init()
|
||||
{
|
||||
OpenSslLegacyShim.EnsureOpenSsl11();
|
||||
}
|
||||
}
|
||||
43
src/__Tests/shared/OpenSslLegacyShim.cs
Normal file
43
src/__Tests/shared/OpenSslLegacyShim.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace StellaOps.Testing;
|
||||
|
||||
/// <summary>
|
||||
/// Ensures OpenSSL 1.1 native libraries are visible on platforms that no longer ship them.
|
||||
/// </summary>
|
||||
public static class OpenSslLegacyShim
|
||||
{
|
||||
private const string LinuxLibraryVariable = "LD_LIBRARY_PATH";
|
||||
|
||||
public static void EnsureOpenSsl11()
|
||||
{
|
||||
if (!OperatingSystem.IsLinux())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var nativeDirectory = Path.Combine(AppContext.BaseDirectory, "native", "linux-x64");
|
||||
if (!Directory.Exists(nativeDirectory))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var current = Environment.GetEnvironmentVariable(LinuxLibraryVariable);
|
||||
if (string.IsNullOrEmpty(current))
|
||||
{
|
||||
Environment.SetEnvironmentVariable(LinuxLibraryVariable, nativeDirectory);
|
||||
return;
|
||||
}
|
||||
|
||||
const char separator = ':';
|
||||
var segments = current.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
if (segments.Contains(nativeDirectory, StringComparer.Ordinal))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Environment.SetEnvironmentVariable(LinuxLibraryVariable, string.Concat(nativeDirectory, separator, current));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user