too much for one commit

This commit is contained in:
Nils Blomgren
2026-05-13 14:01:32 +02:00
parent a96dd33039
commit 328d494530
394 changed files with 98104 additions and 78 deletions

View File

@@ -20,15 +20,18 @@ public class RegisterClusterHandlerTests
[Fact]
public async Task HandleAsync_WithValidRequest_ReturnsSuccessWithClusterId()
{
// Arrange — A valid registration request with all required fields.
// Arrange — A valid registration request with all required fields
// including the tenant and kubeconfig.
RegisterClusterRequest request = new("production-eu", "https://k8s.example.com:6443", "secret-ref");
Guid tenantId = Guid.NewGuid();
Guid environmentId = Guid.NewGuid();
RegisterClusterRequest request = new("production-eu", "https://k8s.example.com:6443", "apiVersion: v1\nkind: Config", tenantId, "prod-context", environmentId);
// Act
Result<Guid> result = await handler.HandleAsync(request);
// Assert — The handler should succeed and the cluster should be persisted.
// Assert — The handler should succeed and the cluster should be persisted with tenant link.
result.IsSuccess.Should().BeTrue();
result.Value.Should().NotBe(Guid.Empty);
@@ -36,6 +39,9 @@ public class RegisterClusterHandlerTests
KubernetesCluster? persisted = await repository.GetByIdAsync(result.Value!);
persisted.Should().NotBeNull();
persisted!.Name.Should().Be("production-eu");
persisted.TenantId.Should().Be(tenantId);
persisted.KubeConfig.Should().Contain("apiVersion");
persisted.ContextName.Should().Be("prod-context");
}
[Fact]
@@ -43,7 +49,7 @@ public class RegisterClusterHandlerTests
{
// Arrange — Missing cluster name.
RegisterClusterRequest request = new("", "https://k8s.example.com:6443", null);
RegisterClusterRequest request = new("", "https://k8s.example.com:6443", "kubeconfig-data", Guid.NewGuid(), "ctx", Guid.NewGuid());
// Act
@@ -60,7 +66,7 @@ public class RegisterClusterHandlerTests
{
// Arrange — Missing API server URL.
RegisterClusterRequest request = new("my-cluster", "", null);
RegisterClusterRequest request = new("my-cluster", "", "kubeconfig-data", Guid.NewGuid(), "ctx", Guid.NewGuid());
// Act
@@ -71,4 +77,56 @@ public class RegisterClusterHandlerTests
result.IsFailure.Should().BeTrue();
result.Error.Should().Contain("API server URL");
}
[Fact]
public async Task HandleAsync_WithEmptyKubeConfig_ReturnsFailure()
{
// Arrange — Missing kubeconfig content. A cluster cannot be registered
// without credentials to access it.
RegisterClusterRequest request = new("my-cluster", "https://k8s.example.com:6443", "", Guid.NewGuid(), "ctx", Guid.NewGuid());
// Act
Result<Guid> result = await handler.HandleAsync(request);
// Assert
result.IsFailure.Should().BeTrue();
result.Error.Should().Contain("KubeConfig");
}
[Fact]
public async Task HandleAsync_WithEmptyTenantId_ReturnsFailure()
{
// Arrange — No tenant specified. Every cluster must belong to a tenant.
RegisterClusterRequest request = new("my-cluster", "https://k8s.example.com:6443", "kubeconfig-data", Guid.Empty, "ctx", Guid.NewGuid());
// Act
Result<Guid> result = await handler.HandleAsync(request);
// Assert
result.IsFailure.Should().BeTrue();
result.Error.Should().Contain("tenant");
}
[Fact]
public async Task HandleAsync_WithEmptyEnvironmentId_ReturnsFailure()
{
// Arrange — No environment specified. Every cluster must belong to an environment.
RegisterClusterRequest request = new("my-cluster", "https://k8s.example.com:6443", "kubeconfig-data", Guid.NewGuid(), "ctx", Guid.Empty);
// Act
Result<Guid> result = await handler.HandleAsync(request);
// Assert
result.IsFailure.Should().BeTrue();
result.Error.Should().Contain("environment");
}
}