2026-07-16 20:53:56 +00:00
|
|
|
using Heimdall.Domain.Entities;
|
|
|
|
|
using Heimdall.Domain.Enums;
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Domain.Tests.Entities;
|
|
|
|
|
|
|
|
|
|
public class AgentTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Create_agent_should_set_properties()
|
|
|
|
|
{
|
2026-07-23 09:52:30 +00:00
|
|
|
var siteId = Guid.NewGuid();
|
|
|
|
|
var agent = new Agent(siteId, "Agent-1", "host-1", "1.0.0");
|
2026-07-16 20:53:56 +00:00
|
|
|
|
|
|
|
|
agent.Id.ShouldNotBe(Guid.Empty);
|
2026-07-23 09:52:30 +00:00
|
|
|
agent.SiteId.ShouldBe(siteId);
|
2026-07-16 20:53:56 +00:00
|
|
|
agent.Name.ShouldBe("Agent-1");
|
|
|
|
|
agent.Hostname.ShouldBe("host-1");
|
|
|
|
|
agent.Version.ShouldBe("1.0.0");
|
|
|
|
|
agent.Status.ShouldBe(AgentStatus.Offline);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-07-23 09:52:30 +00:00
|
|
|
public void Register_should_set_apikey_and_set_online()
|
2026-07-16 20:53:56 +00:00
|
|
|
{
|
|
|
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
|
|
|
|
2026-07-23 09:52:30 +00:00
|
|
|
agent.Register("hash123", "pref");
|
2026-07-16 20:53:56 +00:00
|
|
|
|
2026-07-23 09:52:30 +00:00
|
|
|
agent.ApiKeyHash.ShouldBe("hash123");
|
|
|
|
|
agent.ApiKeyPrefix.ShouldBe("pref");
|
2026-07-16 20:53:56 +00:00
|
|
|
agent.Status.ShouldBe(AgentStatus.Online);
|
|
|
|
|
agent.LastHeartbeat.ShouldNotBeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-07-23 09:52:30 +00:00
|
|
|
public void UpdateHeartbeat_should_set_online()
|
2026-07-16 20:53:56 +00:00
|
|
|
{
|
|
|
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
2026-07-23 09:52:30 +00:00
|
|
|
agent.Register("hash", "pref");
|
2026-07-16 20:53:56 +00:00
|
|
|
|
2026-07-23 09:52:30 +00:00
|
|
|
agent.UpdateHeartbeat();
|
|
|
|
|
|
|
|
|
|
agent.Status.ShouldBe(AgentStatus.Online);
|
|
|
|
|
agent.LastHeartbeat.ShouldNotBeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void UpdateHeartbeat_with_ip_should_update()
|
|
|
|
|
{
|
|
|
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
|
|
|
agent.Register("hash", "pref");
|
2026-07-16 20:53:56 +00:00
|
|
|
|
|
|
|
|
agent.UpdateHeartbeat("1.2.3.4");
|
|
|
|
|
|
|
|
|
|
agent.PublicIp.ShouldBe("1.2.3.4");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-07-23 09:52:30 +00:00
|
|
|
public void MarkOffline_should_set_status()
|
2026-07-16 20:53:56 +00:00
|
|
|
{
|
|
|
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
2026-07-23 09:52:30 +00:00
|
|
|
agent.Register("hash", "pref");
|
2026-07-16 20:53:56 +00:00
|
|
|
|
|
|
|
|
agent.MarkOffline();
|
|
|
|
|
|
|
|
|
|
agent.Status.ShouldBe(AgentStatus.Offline);
|
|
|
|
|
}
|
2026-07-23 09:52:30 +00:00
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MarkError_should_set_status()
|
|
|
|
|
{
|
|
|
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
|
|
|
|
|
|
|
|
agent.MarkError();
|
|
|
|
|
|
|
|
|
|
agent.Status.ShouldBe(AgentStatus.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void UpdateCapabilities_should_update_all_fields()
|
|
|
|
|
{
|
|
|
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
|
|
|
|
|
|
|
|
agent.UpdateCapabilities(true, 8, 16384, GpuAcceleration.NvidiaCuda);
|
|
|
|
|
|
|
|
|
|
agent.HasGpu.ShouldBeTrue();
|
|
|
|
|
agent.CpuCores.ShouldBe(8);
|
|
|
|
|
agent.MemoryMb.ShouldBe(16384);
|
|
|
|
|
agent.GpuType.ShouldBe(GpuAcceleration.NvidiaCuda);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SoftDelete_should_set_deleted_flag()
|
|
|
|
|
{
|
|
|
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
|
|
|
|
|
|
|
|
agent.SoftDelete();
|
|
|
|
|
|
|
|
|
|
agent.IsDeleted.ShouldBeTrue();
|
|
|
|
|
agent.DeletedAt.ShouldNotBeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Cameras_collection_should_be_empty_by_default()
|
|
|
|
|
{
|
|
|
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
|
|
|
|
|
|
|
|
agent.Cameras.ShouldBeEmpty();
|
|
|
|
|
}
|
2026-07-16 20:53:56 +00:00
|
|
|
}
|