Add unit tests for KubernetesCluster, Tenant, ServiceInstance, and RegisterClusterHandler
- Implement tests for KubernetesCluster including registration, connectivity status, and error handling. - Create tests for Tenant creation, member management, and status changes. - Add tests for ServiceInstance provisioning and state management. - Introduce RegisterClusterHandler tests to validate registration requests and error scenarios. - Set up project files for new test projects with necessary dependencies.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using EntKube.Provisioning.Domain;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace EntKube.Provisioning.Tests.Domain;
|
||||
|
||||
public class ServiceInstanceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Provision_WithValidInputs_CreatesInstanceInPendingState()
|
||||
{
|
||||
// Arrange & Act — Request provisioning of a MinIO instance.
|
||||
|
||||
Guid clusterId = Guid.NewGuid();
|
||||
|
||||
ServiceInstance instance = ServiceInstance.Provision(
|
||||
clusterId,
|
||||
ServiceType.MinIO,
|
||||
"tenant-storage",
|
||||
"minio-system");
|
||||
|
||||
// Assert — Starts pending until the reconciler deploys it.
|
||||
|
||||
instance.Id.Should().NotBe(Guid.Empty);
|
||||
instance.ClusterId.Should().Be(clusterId);
|
||||
instance.ServiceType.Should().Be(ServiceType.MinIO);
|
||||
instance.Name.Should().Be("tenant-storage");
|
||||
instance.Namespace.Should().Be("minio-system");
|
||||
instance.DesiredState.Should().Be(ServiceState.Running);
|
||||
instance.CurrentState.Should().Be(ServiceState.Pending);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Provision_WithEmptyName_ThrowsArgumentException()
|
||||
{
|
||||
// Arrange & Act
|
||||
|
||||
Action act = () => ServiceInstance.Provision(Guid.NewGuid(), ServiceType.MinIO, "", "ns");
|
||||
|
||||
// Assert
|
||||
|
||||
act.Should().Throw<ArgumentException>()
|
||||
.WithParameterName("name");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MarkRunning_UpdatesCurrentState()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
ServiceInstance instance = ServiceInstance.Provision(Guid.NewGuid(), ServiceType.CloudNativePG, "db", "cnpg-system");
|
||||
|
||||
// Act
|
||||
|
||||
instance.MarkRunning();
|
||||
|
||||
// Assert
|
||||
|
||||
instance.CurrentState.Should().Be(ServiceState.Running);
|
||||
instance.LastReconcileAt.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestDecommission_SetsDesiredStateToDecommissioned()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
ServiceInstance instance = ServiceInstance.Provision(Guid.NewGuid(), ServiceType.Keycloak, "auth", "keycloak-system");
|
||||
instance.MarkRunning();
|
||||
|
||||
// Act — Tenant admin decides to tear down this service.
|
||||
|
||||
instance.RequestDecommission();
|
||||
|
||||
// Assert — Desired state changes but current state remains until reconciler acts.
|
||||
|
||||
instance.DesiredState.Should().Be(ServiceState.Decommissioned);
|
||||
instance.CurrentState.Should().Be(ServiceState.Running);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="FluentAssertions" Version="8.9.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\EntKube.Provisioning\EntKube.Provisioning.csproj" />
|
||||
<ProjectReference Include="..\..\src\EntKube.SharedKernel\EntKube.SharedKernel.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user