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