Files
JiboExperiments/OpenJibo/tests/Jibo.Cloud.Tests/Protocol/FileProtocolTelemetrySinkTests.cs

62 lines
2.3 KiB
C#
Raw Normal View History

2026-04-15 11:58:58 -05:00
using Jibo.Cloud.Domain.Models;
using Jibo.Cloud.Infrastructure.Telemetry;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
namespace Jibo.Cloud.Tests.Protocol;
public sealed class FileProtocolTelemetrySinkTests : IDisposable
{
private readonly string _appBaseDirectory;
2026-05-17 08:08:11 -05:00
private readonly string _repoRoot;
private readonly string _workspaceRoot;
2026-04-15 11:58:58 -05:00
public FileProtocolTelemetrySinkTests()
{
2026-05-17 08:08:11 -05:00
_workspaceRoot = Path.Combine(Path.GetTempPath(), "OpenJibo.ProtocolTelemetry.Tests",
Guid.NewGuid().ToString("N"));
2026-04-15 11:58:58 -05:00
_repoRoot = Path.Combine(_workspaceRoot, "OpenJibo");
2026-05-17 08:08:11 -05:00
_appBaseDirectory = Path.Combine(_repoRoot, "src", "Jibo.Cloud", "dotnet", "src", "Jibo.Cloud.Api", "bin",
"Debug", "net10.0");
2026-04-15 11:58:58 -05:00
Directory.CreateDirectory(_repoRoot);
Directory.CreateDirectory(_appBaseDirectory);
File.WriteAllText(Path.Combine(_repoRoot, "OpenJibo.slnx"), string.Empty);
}
2026-05-17 08:08:11 -05:00
public void Dispose()
{
if (Directory.Exists(_workspaceRoot)) Directory.Delete(_workspaceRoot, true);
}
2026-04-15 11:58:58 -05:00
[Fact]
public async Task RecordAsync_ResolvesRelativePathAgainstOpenJiboRepoRoot()
{
var captureDirectory = CapturePathResolver.Resolve("captures/http", _repoRoot, _appBaseDirectory);
var sink = new FileProtocolTelemetrySink(
NullLogger<FileProtocolTelemetrySink>.Instance,
Options.Create(new ProtocolTelemetryOptions
{
Enabled = true,
DirectoryPath = captureDirectory
}));
var envelope = new ProtocolEnvelope
{
HostName = "api.jibo.com",
Method = "POST",
Path = "/",
ServicePrefix = "Notification_20150505",
Operation = "NewRobotToken",
BodyText = """{"deviceId":"robot-123"}"""
};
await sink.RecordAsync(envelope, ProtocolDispatchResult.Ok(new { token = "token-robot-123" }));
var captureFile = Directory.GetFiles(captureDirectory, "*.events.ndjson").Single();
var contents = await File.ReadAllTextAsync(captureFile);
Assert.Contains("Notification_20150505", contents);
Assert.DoesNotContain(Path.Combine("bin", "Debug"), captureFile, StringComparison.OrdinalIgnoreCase);
}
2026-05-17 08:08:11 -05:00
}