test(secrets-cli): clean up temp dirs in TargetConfigReaderTests

This commit is contained in:
Joseph Doherty
2026-07-19 08:54:54 -04:00
parent b9a57fe06e
commit b8c6c7d432
@@ -8,12 +8,26 @@ namespace ZB.MOM.WW.Secrets.Tests.Cli.Interactive;
/// (base json + optional environment overlay + environment variables) exactly the way the app
/// would at startup, so fixes land in the store the app actually reads.
/// </summary>
public sealed class TargetConfigReaderTests
public sealed class TargetConfigReaderTests : IDisposable
{
private static string NewTempDir()
private readonly List<string> _tempDirs = [];
public void Dispose()
{
foreach (string dir in _tempDirs)
{
if (Directory.Exists(dir))
{
try { Directory.Delete(dir, recursive: true); } catch (IOException) { /* best-effort temp cleanup */ }
}
}
}
private string NewTempDir()
{
string dir = Path.Combine(Path.GetTempPath(), "zb-secrets-cfg-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
_tempDirs.Add(dir);
return dir;
}