finish off sprint advisories and sprints
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
@@ -11,48 +12,45 @@ using StellaOps.Signals.Services;
|
||||
|
||||
namespace StellaOps.Signals.Tests.TestInfrastructure;
|
||||
|
||||
public sealed class SignalsTestFactory : WebApplicationFactory<Program>, IAsyncLifetime
|
||||
public sealed class SignalsTestFactory : IAsyncLifetime, IDisposable
|
||||
{
|
||||
private readonly string storagePath;
|
||||
private readonly InternalWebAppFactory _inner;
|
||||
private readonly string _storagePath;
|
||||
|
||||
public SignalsTestFactory()
|
||||
{
|
||||
storagePath = Path.Combine(Path.GetTempPath(), "signals-tests", Guid.NewGuid().ToString());
|
||||
Directory.CreateDirectory(storagePath);
|
||||
_storagePath = Path.Combine(Path.GetTempPath(), "signals-tests", Guid.NewGuid().ToString());
|
||||
Directory.CreateDirectory(_storagePath);
|
||||
_inner = new InternalWebAppFactory(_storagePath);
|
||||
}
|
||||
|
||||
public string StoragePath => storagePath;
|
||||
public string StoragePath => _storagePath;
|
||||
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureAppConfiguration((context, configuration) =>
|
||||
{
|
||||
var settings = new Dictionary<string, string?>
|
||||
{
|
||||
["Signals:Authority:Enabled"] = "false",
|
||||
["Signals:Authority:AllowAnonymousFallback"] = "true",
|
||||
["Signals:Storage:RootPath"] = storagePath
|
||||
};
|
||||
public IServiceProvider Services => _inner.Services;
|
||||
|
||||
configuration.AddInMemoryCollection(settings);
|
||||
});
|
||||
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
services.RemoveAll<IReachabilityCache>();
|
||||
services.AddSingleton<IReachabilityCache, InMemoryReachabilityCache>();
|
||||
});
|
||||
}
|
||||
public HttpClient CreateClient() => _inner.CreateClient();
|
||||
|
||||
public ValueTask InitializeAsync() => ValueTask.CompletedTask;
|
||||
|
||||
public new async ValueTask DisposeAsync()
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await _inner.DisposeAsync();
|
||||
CleanupStorage();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_inner.Dispose();
|
||||
CleanupStorage();
|
||||
}
|
||||
|
||||
private void CleanupStorage()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(storagePath))
|
||||
if (Directory.Exists(_storagePath))
|
||||
{
|
||||
Directory.Delete(storagePath, recursive: true);
|
||||
Directory.Delete(_storagePath, recursive: true);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -60,7 +58,35 @@ public sealed class SignalsTestFactory : WebApplicationFactory<Program>, IAsyncL
|
||||
// best effort cleanup.
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class InternalWebAppFactory : WebApplicationFactory<Program>
|
||||
{
|
||||
private readonly string _storagePath;
|
||||
|
||||
public InternalWebAppFactory(string storagePath)
|
||||
{
|
||||
_storagePath = storagePath;
|
||||
}
|
||||
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureAppConfiguration((context, configuration) =>
|
||||
{
|
||||
var settings = new Dictionary<string, string?>
|
||||
{
|
||||
["Signals:Authority:Enabled"] = "false",
|
||||
["Signals:Authority:AllowAnonymousFallback"] = "true",
|
||||
["Signals:Storage:RootPath"] = _storagePath
|
||||
};
|
||||
|
||||
configuration.AddInMemoryCollection(settings);
|
||||
});
|
||||
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
services.RemoveAll<IReachabilityCache>();
|
||||
services.AddSingleton<IReachabilityCache, InMemoryReachabilityCache>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user