Files
Heimdall/tests/Heimdall.Agent.Tests/AgentHealthCheckTests.cs
T
Arnaud Dartois 3fc42be4b2 test(agent): add unit tests for AgentState, AgentHealthCheck, AgentRegistrationService
13 tests covering:
- AgentState file persistence (save, load, corrupt file, empty ID, clear)
- AgentHealthCheck (healthy, degraded, unhealthy states)
- AgentRegistrationService (successful registration, retry on failure,
  all retries exhausted, reuse existing identity, offline heartbeat on stop)
2026-07-18 14:16:13 +00:00

41 lines
1.2 KiB
C#

using Heimdall.Agent.Services;
using Microsoft.Extensions.Diagnostics.HealthChecks;
namespace Heimdall.Agent.Tests;
public class AgentHealthCheckTests
{
[Fact]
public async Task CheckHealth_WhenRegistered_ReturnsHealthy()
{
var state = new AgentState { AgentId = Guid.NewGuid(), ApiKey = "valid-key" };
var check = new AgentHealthCheck(state);
var result = await check.CheckHealthAsync(new HealthCheckContext());
result.Status.ShouldBe(HealthStatus.Healthy);
}
[Fact]
public async Task CheckHealth_WhenNotRegistered_ReturnsUnhealthy()
{
var state = new AgentState { AgentId = Guid.Empty };
var check = new AgentHealthCheck(state);
var result = await check.CheckHealthAsync(new HealthCheckContext());
result.Status.ShouldBe(HealthStatus.Unhealthy);
}
[Fact]
public async Task CheckHealth_WhenNoApiKey_ReturnsDegraded()
{
var state = new AgentState { AgentId = Guid.NewGuid(), ApiKey = null };
var check = new AgentHealthCheck(state);
var result = await check.CheckHealthAsync(new HealthCheckContext());
result.Status.ShouldBe(HealthStatus.Degraded);
}
}