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)
41 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|