up
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled

This commit is contained in:
Vladimir Moushkov
2025-10-24 19:19:23 +03:00
parent 17d861e4ab
commit b51037a9b8
72 changed files with 6070 additions and 151 deletions

View File

@@ -0,0 +1,60 @@
using System.Linq;
using StellaOps.Zastava.Observer.Runtime;
using StellaOps.Zastava.Observer.Tests.TestSupport;
using Xunit;
namespace StellaOps.Zastava.Observer.Tests.Runtime;
public sealed class ElfBuildIdReaderTests
{
[Fact]
public async Task TryReadBuildIdAsync_ReturnsExpectedHex()
{
using var temp = new TempDirectory();
var elfPath = Path.Combine(temp.RootPath, "bin", "example");
var buildIdBytes = Enumerable.Range(0, 20).Select(static index => (byte)(index + 1)).ToArray();
ElfTestFileBuilder.CreateElfWithBuildId(elfPath, buildIdBytes);
var buildId = await ElfBuildIdReader.TryReadBuildIdAsync(elfPath, CancellationToken.None);
Assert.Equal(Convert.ToHexString(buildIdBytes).ToLowerInvariant(), buildId);
}
[Fact]
public async Task TryReadBuildIdAsync_InvalidFileReturnsNull()
{
using var temp = new TempDirectory();
var path = Path.Combine(temp.RootPath, "bin", "invalid");
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
await File.WriteAllTextAsync(path, "not-an-elf");
var buildId = await ElfBuildIdReader.TryReadBuildIdAsync(path, CancellationToken.None);
Assert.Null(buildId);
}
private sealed class TempDirectory : IDisposable
{
public TempDirectory()
{
RootPath = Path.Combine(Path.GetTempPath(), "elf-buildid-tests", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(RootPath);
}
public string RootPath { get; }
public void Dispose()
{
try
{
if (Directory.Exists(RootPath))
{
Directory.Delete(RootPath, recursive: true);
}
}
catch
{
}
}
}
}