too much for one commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using EntKube.Clusters.Domain;
|
||||
using EntKube.Clusters.Features.UpdateClusterStatus;
|
||||
using EntKube.Clusters.Infrastructure;
|
||||
using EntKube.SharedKernel.Domain;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace EntKube.Clusters.Tests.Features;
|
||||
|
||||
public class UpdateClusterStatusHandlerTests
|
||||
{
|
||||
private readonly UpdateClusterStatusHandler handler;
|
||||
private readonly InMemoryClusterRepository repository;
|
||||
|
||||
public UpdateClusterStatusHandlerTests()
|
||||
{
|
||||
repository = new InMemoryClusterRepository();
|
||||
handler = new UpdateClusterStatusHandler(repository);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_MarkConnected_UpdatesClusterStatus()
|
||||
{
|
||||
// Arrange — A pending cluster exists.
|
||||
|
||||
KubernetesCluster cluster = KubernetesCluster.Register(
|
||||
"production",
|
||||
"https://k8s.example.com:6443",
|
||||
"kubeconfig-data",
|
||||
Guid.NewGuid(),
|
||||
"prod-ctx", Guid.NewGuid());
|
||||
|
||||
await repository.AddAsync(cluster);
|
||||
|
||||
// Act — Mark it as connected (health check passed).
|
||||
|
||||
Result result = await handler.HandleAsync(
|
||||
new UpdateClusterStatusRequest(cluster.Id, ClusterStatus.Connected));
|
||||
|
||||
// Assert
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
|
||||
KubernetesCluster? updated = await repository.GetByIdAsync(cluster.Id);
|
||||
updated!.Status.Should().Be(ClusterStatus.Connected);
|
||||
updated.LastHealthCheckAt.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_MarkUnreachable_UpdatesClusterStatus()
|
||||
{
|
||||
// Arrange — A connected cluster.
|
||||
|
||||
KubernetesCluster cluster = KubernetesCluster.Register(
|
||||
"staging",
|
||||
"https://staging-k8s.example.com:6443",
|
||||
"kubeconfig-data",
|
||||
Guid.NewGuid(),
|
||||
"staging-ctx", Guid.NewGuid());
|
||||
|
||||
cluster.MarkConnected();
|
||||
await repository.AddAsync(cluster);
|
||||
|
||||
// Act — Health check fails.
|
||||
|
||||
Result result = await handler.HandleAsync(
|
||||
new UpdateClusterStatusRequest(cluster.Id, ClusterStatus.Unreachable));
|
||||
|
||||
// Assert
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
|
||||
KubernetesCluster? updated = await repository.GetByIdAsync(cluster.Id);
|
||||
updated!.Status.Should().Be(ClusterStatus.Unreachable);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WithNonExistentCluster_ReturnsFailure()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Guid unknownId = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
|
||||
Result result = await handler.HandleAsync(
|
||||
new UpdateClusterStatusRequest(unknownId, ClusterStatus.Connected));
|
||||
|
||||
// Assert
|
||||
|
||||
result.IsFailure.Should().BeTrue();
|
||||
result.Error.Should().Contain("not found");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user