up
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled

This commit is contained in:
StellaOps Bot
2025-12-13 00:20:26 +02:00
parent e1f1bef4c1
commit 564df71bfb
2376 changed files with 334389 additions and 328032 deletions

View File

@@ -1,100 +1,100 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using StellaOps.Notify.Engine;
using StellaOps.Notify.Models;
using Xunit;
namespace StellaOps.Notify.Connectors.Email.Tests;
public sealed class EmailChannelHealthProviderTests
{
private static readonly EmailChannelHealthProvider Provider = new();
[Fact]
public async Task CheckAsync_ReturnsHealthy()
{
var channel = CreateChannel(enabled: true, target: "ops@example.com");
var context = new ChannelHealthContext(
channel.TenantId,
channel,
channel.Config.Target!,
new DateTimeOffset(2025, 10, 20, 15, 0, 0, TimeSpan.Zero),
"trace-email-001");
var result = await Provider.CheckAsync(context, CancellationToken.None);
Assert.Equal(ChannelHealthStatus.Healthy, result.Status);
Assert.Equal("true", result.Metadata["email.channel.enabled"]);
Assert.Equal("true", result.Metadata["email.validation.targetPresent"]);
Assert.Equal("ops@example.com", result.Metadata["email.target"]);
}
[Fact]
public async Task CheckAsync_ReturnsDegradedWhenDisabled()
{
var channel = CreateChannel(enabled: false, target: "ops@example.com");
var context = new ChannelHealthContext(
channel.TenantId,
channel,
channel.Config.Target!,
DateTimeOffset.UtcNow,
"trace-email-002");
var result = await Provider.CheckAsync(context, CancellationToken.None);
Assert.Equal(ChannelHealthStatus.Degraded, result.Status);
Assert.Equal("false", result.Metadata["email.channel.enabled"]);
}
[Fact]
public async Task CheckAsync_ReturnsUnhealthyWhenTargetMissing()
{
var channel = NotifyChannel.Create(
channelId: "channel-email-ops",
tenantId: "tenant-sec",
name: "email:ops",
type: NotifyChannelType.Email,
config: NotifyChannelConfig.Create(
secretRef: "ref://notify/channels/email/ops",
target: null,
properties: new Dictionary<string, string>
{
["smtpHost"] = "smtp.ops.example.com"
}),
enabled: true);
var context = new ChannelHealthContext(
channel.TenantId,
channel,
channel.Name,
DateTimeOffset.UtcNow,
"trace-email-003");
var result = await Provider.CheckAsync(context, CancellationToken.None);
Assert.Equal(ChannelHealthStatus.Unhealthy, result.Status);
Assert.Equal("false", result.Metadata["email.validation.targetPresent"]);
}
private static NotifyChannel CreateChannel(bool enabled, string? target)
{
return NotifyChannel.Create(
channelId: "channel-email-ops",
tenantId: "tenant-sec",
name: "email:ops",
type: NotifyChannelType.Email,
config: NotifyChannelConfig.Create(
secretRef: "ref://notify/channels/email/ops",
target: target,
properties: new Dictionary<string, string>
{
["smtpHost"] = "smtp.ops.example.com",
["password"] = "super-secret"
}),
enabled: enabled);
}
}
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using StellaOps.Notify.Engine;
using StellaOps.Notify.Models;
using Xunit;
namespace StellaOps.Notify.Connectors.Email.Tests;
public sealed class EmailChannelHealthProviderTests
{
private static readonly EmailChannelHealthProvider Provider = new();
[Fact]
public async Task CheckAsync_ReturnsHealthy()
{
var channel = CreateChannel(enabled: true, target: "ops@example.com");
var context = new ChannelHealthContext(
channel.TenantId,
channel,
channel.Config.Target!,
new DateTimeOffset(2025, 10, 20, 15, 0, 0, TimeSpan.Zero),
"trace-email-001");
var result = await Provider.CheckAsync(context, CancellationToken.None);
Assert.Equal(ChannelHealthStatus.Healthy, result.Status);
Assert.Equal("true", result.Metadata["email.channel.enabled"]);
Assert.Equal("true", result.Metadata["email.validation.targetPresent"]);
Assert.Equal("ops@example.com", result.Metadata["email.target"]);
}
[Fact]
public async Task CheckAsync_ReturnsDegradedWhenDisabled()
{
var channel = CreateChannel(enabled: false, target: "ops@example.com");
var context = new ChannelHealthContext(
channel.TenantId,
channel,
channel.Config.Target!,
DateTimeOffset.UtcNow,
"trace-email-002");
var result = await Provider.CheckAsync(context, CancellationToken.None);
Assert.Equal(ChannelHealthStatus.Degraded, result.Status);
Assert.Equal("false", result.Metadata["email.channel.enabled"]);
}
[Fact]
public async Task CheckAsync_ReturnsUnhealthyWhenTargetMissing()
{
var channel = NotifyChannel.Create(
channelId: "channel-email-ops",
tenantId: "tenant-sec",
name: "email:ops",
type: NotifyChannelType.Email,
config: NotifyChannelConfig.Create(
secretRef: "ref://notify/channels/email/ops",
target: null,
properties: new Dictionary<string, string>
{
["smtpHost"] = "smtp.ops.example.com"
}),
enabled: true);
var context = new ChannelHealthContext(
channel.TenantId,
channel,
channel.Name,
DateTimeOffset.UtcNow,
"trace-email-003");
var result = await Provider.CheckAsync(context, CancellationToken.None);
Assert.Equal(ChannelHealthStatus.Unhealthy, result.Status);
Assert.Equal("false", result.Metadata["email.validation.targetPresent"]);
}
private static NotifyChannel CreateChannel(bool enabled, string? target)
{
return NotifyChannel.Create(
channelId: "channel-email-ops",
tenantId: "tenant-sec",
name: "email:ops",
type: NotifyChannelType.Email,
config: NotifyChannelConfig.Create(
secretRef: "ref://notify/channels/email/ops",
target: target,
properties: new Dictionary<string, string>
{
["smtpHost"] = "smtp.ops.example.com",
["password"] = "super-secret"
}),
enabled: enabled);
}
}