Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Merge pull request #138 Co-authored-by: Arnaud Dartois <admin@tordais.cc>
129 lines
4.2 KiB
C#
129 lines
4.2 KiB
C#
using Heimdall.Agent.Services;
|
|
|
|
namespace Heimdall.Agent.Tests;
|
|
|
|
public class CameraConfigStoreTests
|
|
{
|
|
[Fact]
|
|
public void EmptyStore_NoCameras()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
store.Cameras.ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void SetLocalFallback_ReturnedBeforeCentralConfig()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
var camera = new AgentCameraConfig(Guid.NewGuid(), "Locale", "rtsp://local/stream", null, true);
|
|
store.SetLocalFallback([camera]);
|
|
store.Cameras.ShouldBe([camera]);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyCameraSetting_AssemblesConfigFromKeys()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
var id = Guid.NewGuid();
|
|
var changed = 0;
|
|
store.Changed += (_, _) => changed++;
|
|
|
|
store.ApplyCameraSetting($"camera.{id}.name", "Entrée");
|
|
store.ApplyCameraSetting($"camera.{id}.rtsp", "rtsp://cam/stream");
|
|
store.ApplyCameraSetting($"camera.{id}.sub_rtsp", "rtsp://cam/sub");
|
|
store.ApplyCameraSetting($"camera.{id}.enabled", "true");
|
|
|
|
var camera = store.Cameras.ShouldHaveSingleItem();
|
|
camera.CameraId.ShouldBe(id);
|
|
camera.Name.ShouldBe("Entrée");
|
|
camera.RtspUrl.ShouldBe("rtsp://cam/stream");
|
|
camera.SubRtspUrl.ShouldBe("rtsp://cam/sub");
|
|
camera.Enabled.ShouldBeTrue();
|
|
camera.EffectiveRtspUrl.ShouldBe("rtsp://cam/sub");
|
|
changed.ShouldBe(4);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyCameraSetting_EnabledFalse_Parsed()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
var id = Guid.NewGuid();
|
|
store.ApplyCameraSetting($"camera.{id}.enabled", "false");
|
|
store.Cameras.ShouldHaveSingleItem().Enabled.ShouldBeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyCameraSetting_RecordingIsOptInAndPropagates()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
var id = Guid.NewGuid();
|
|
store.ApplyCameraSetting($"camera.{id}.name", "Door");
|
|
store.Cameras.ShouldHaveSingleItem().RecordingEnabled.ShouldBeFalse();
|
|
|
|
store.ApplyCameraSetting($"camera.{id}.recording_enabled", "true");
|
|
|
|
store.Cameras.ShouldHaveSingleItem().RecordingEnabled.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyCameraSetting_EventRecordingIsOptInAndPropagates()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
var id = Guid.NewGuid();
|
|
store.ApplyCameraSetting($"camera.{id}.name", "Door");
|
|
store.Cameras.ShouldHaveSingleItem().EventRecordingEnabled.ShouldBeFalse();
|
|
|
|
store.ApplyCameraSetting($"camera.{id}.event_recording_enabled", "true");
|
|
|
|
store.Cameras.ShouldHaveSingleItem().EventRecordingEnabled.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyCameraSetting_InvalidKey_Ignored()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
var changed = 0;
|
|
store.Changed += (_, _) => changed++;
|
|
|
|
store.ApplyCameraSetting("camera.not-a-guid.rtsp", "rtsp://x");
|
|
store.ApplyCameraSetting("other.key", "value");
|
|
|
|
store.Cameras.ShouldBeEmpty();
|
|
changed.ShouldBe(0);
|
|
}
|
|
|
|
[Fact]
|
|
public void MarkCentralReceived_DropsLocalFallbackEvenIfEmpty()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
store.SetLocalFallback([new AgentCameraConfig(Guid.NewGuid(), "L", "rtsp://l", null, true)]);
|
|
store.MarkCentralReceived();
|
|
store.Cameras.ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void MarkCentralReceived_KeepsCentralCameras()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
store.SetLocalFallback([new AgentCameraConfig(Guid.NewGuid(), "L", "rtsp://l", null, true)]);
|
|
var id = Guid.NewGuid();
|
|
store.ApplyCameraSetting($"camera.{id}.rtsp", "rtsp://c");
|
|
store.MarkCentralReceived();
|
|
|
|
var camera = store.Cameras.ShouldHaveSingleItem();
|
|
camera.CameraId.ShouldBe(id);
|
|
camera.RtspUrl.ShouldBe("rtsp://c");
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyCameraSetting_WithoutRtspUrl_StillShipped()
|
|
{
|
|
var store = new CameraConfigStore();
|
|
var id = Guid.NewGuid();
|
|
store.ApplyCameraSetting($"camera.{id}.name", "No flux");
|
|
var camera = store.Cameras.ShouldHaveSingleItem();
|
|
camera.Name.ShouldBe("No flux");
|
|
camera.RtspUrl.ShouldBeEmpty();
|
|
}
|
|
}
|