Premiere commit - Omika
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using System.Text.Json;
|
||||
using Omika.Core.Observability.External;
|
||||
using Omika.Core.Observability.Outbox;
|
||||
|
||||
namespace Omika.Tests.Observability.Forwarding;
|
||||
|
||||
/// <summary>Fabrique de test partagée pour le forwarder T19.</summary>
|
||||
internal static class ForwardingTestHarness
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
|
||||
|
||||
public static string CreateTempDirectory()
|
||||
{
|
||||
string dir = Path.Combine(Path.GetTempPath(), "omika-forwarding-tests", Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static void DeleteDirectory(string dir)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(dir))
|
||||
{
|
||||
Directory.Delete(dir, recursive: true);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Best-effort.
|
||||
}
|
||||
}
|
||||
|
||||
public static RemoteDiagnosticRecord NewRecord(
|
||||
string clientCode = "BATIK.01",
|
||||
string component = "test",
|
||||
Guid? eventId = null,
|
||||
string? screenCode = null,
|
||||
string? featureCode = null) =>
|
||||
new()
|
||||
{
|
||||
ReceivedAtUtc = DateTimeOffset.UtcNow,
|
||||
BatchId = Guid.NewGuid(),
|
||||
IngestionTraceId = Guid.NewGuid().ToString("D"),
|
||||
ClientCode = clientCode,
|
||||
ActorKey = "a" + new string('0', 63),
|
||||
ActorKeyVersion = 1,
|
||||
DeviceKey = "d" + new string('0', 63),
|
||||
DeviceKeyVersion = 1,
|
||||
LicenseNumber = "b600a641d61c485b8e928cd3aab281b1",
|
||||
ServerInstance = "API-SRV-01",
|
||||
Environment = "Production",
|
||||
Event = new DiagnosticEventDto
|
||||
{
|
||||
EventId = eventId ?? Guid.NewGuid(),
|
||||
EventCode = "OMK-MOB-APP-001",
|
||||
TimestampUtc = DateTimeOffset.UtcNow,
|
||||
Level = "Info",
|
||||
Priority = "P3",
|
||||
Component = component,
|
||||
ScreenCode = screenCode,
|
||||
FeatureCode = featureCode
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>Sérialise un enregistrement au format JSONL canonique (camelCase).</summary>
|
||||
public static string Serialize(RemoteDiagnosticRecord record) =>
|
||||
JsonSerializer.Serialize(record, JsonOptions);
|
||||
|
||||
/// <summary>Écrit un fichier JSONL de spool (nom exact, ex. omika-mobile-diagnostic-20261002-001.jsonl).</summary>
|
||||
public static void WriteSpoolFile(string directory, string fileName, IReadOnlyList<RemoteDiagnosticRecord> records)
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
File.WriteAllLines(Path.Combine(directory, fileName), records.Select(Serialize));
|
||||
}
|
||||
|
||||
/// <summary>Écrit un fichier de spool avec un contenu brut arbitraire (tests quota/taille).</summary>
|
||||
public static void WriteRawSpoolFile(string directory, string fileName, string content)
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
File.WriteAllText(Path.Combine(directory, fileName), content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user