gateway api fixes
This commit is contained in:
@@ -826,10 +826,10 @@ public class CnpgServiceTests : IDisposable
|
||||
|
||||
(Tenant tenant, KubernetesCluster cluster, StorageLink storageLink) = await SeedTenantWithClusterAsync();
|
||||
|
||||
string? appliedManifest = null;
|
||||
List<string> appliedManifests = [];
|
||||
k8sFactory.Setup(f => f.ApplyManifestAsync(
|
||||
It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, string, CancellationToken>((manifest, _, _) => appliedManifest = manifest)
|
||||
.Callback<string, string, CancellationToken>((manifest, _, _) => appliedManifests.Add(manifest))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
@@ -838,9 +838,113 @@ public class CnpgServiceTests : IDisposable
|
||||
tenant.Id, cluster.Id, "sched-test", "databases", 3, "10Gi",
|
||||
storageLink.Id, "0 0 2 * * *");
|
||||
|
||||
// Assert — a ScheduledBackup resource should be in the manifest.
|
||||
// Assert — ObjectStore and ScheduledBackup are applied in separate calls.
|
||||
|
||||
appliedManifest.Should().Contain("ScheduledBackup");
|
||||
appliedManifest.Should().Contain("0 0 2 * * *");
|
||||
string allManifests = string.Join("\n", appliedManifests);
|
||||
appliedManifests.Should().Contain(m => m.Contains("ObjectStore"));
|
||||
appliedManifests.Should().Contain(m => m.Contains("ScheduledBackup"));
|
||||
appliedManifests.Should().Contain(m => m.Contains("0 0 2 * * *"));
|
||||
appliedManifests.Should().Contain(m => m.Contains("immediate: true"));
|
||||
}
|
||||
|
||||
// ──────── GetDatabaseCredentialsAsync ────────
|
||||
|
||||
[Fact]
|
||||
public async Task GetDatabaseCredentialsAsync_ReturnsDecryptedCredentials()
|
||||
{
|
||||
// Arrange — create a cluster and database so the vault has credentials.
|
||||
|
||||
(Tenant tenant, KubernetesCluster cluster, _) = await SeedTenantWithClusterAsync();
|
||||
|
||||
CnpgCluster cnpg = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
TenantId = tenant.Id,
|
||||
KubernetesClusterId = cluster.Id,
|
||||
Name = "creds-cluster",
|
||||
Namespace = "databases",
|
||||
PostgresVersion = "18",
|
||||
StorageSize = "10Gi",
|
||||
Status = CnpgClusterStatus.Running
|
||||
};
|
||||
|
||||
db.CnpgClusters.Add(cnpg);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
k8sFactory.Setup(f => f.ExecuteSqlAsync(
|
||||
It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
CnpgDatabase database = await sut.CreateDatabaseAsync(tenant.Id, cnpg.Id, "webapp");
|
||||
|
||||
// Act — retrieve the credentials from the vault.
|
||||
|
||||
Dictionary<string, string> credentials = await sut.GetDatabaseCredentialsAsync(
|
||||
tenant.Id, database.Id);
|
||||
|
||||
// Assert — all connection fields should be present with correct values.
|
||||
|
||||
credentials.Should().ContainKey("HOST")
|
||||
.WhoseValue.Should().Be("creds-cluster-rw.databases.svc.cluster.local");
|
||||
credentials.Should().ContainKey("PORT").WhoseValue.Should().Be("5432");
|
||||
credentials.Should().ContainKey("DATABASE").WhoseValue.Should().Be("webapp");
|
||||
credentials.Should().ContainKey("USERNAME").WhoseValue.Should().Be("webapp_owner");
|
||||
credentials.Should().ContainKey("PASSWORD");
|
||||
credentials["PASSWORD"].Should().HaveLength(32);
|
||||
}
|
||||
|
||||
// ──────── SyncDatabaseCredentialsToK8sAsync ────────
|
||||
|
||||
[Fact]
|
||||
public async Task SyncDatabaseCredentialsToK8sAsync_AppliesK8sSecretManifest()
|
||||
{
|
||||
// Arrange — create a cluster and database with vault credentials.
|
||||
|
||||
(Tenant tenant, KubernetesCluster cluster, _) = await SeedTenantWithClusterAsync();
|
||||
|
||||
CnpgCluster cnpg = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
TenantId = tenant.Id,
|
||||
KubernetesClusterId = cluster.Id,
|
||||
Name = "sync-cluster",
|
||||
Namespace = "databases",
|
||||
PostgresVersion = "18",
|
||||
StorageSize = "10Gi",
|
||||
Status = CnpgClusterStatus.Running
|
||||
};
|
||||
|
||||
db.CnpgClusters.Add(cnpg);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
k8sFactory.Setup(f => f.ExecuteSqlAsync(
|
||||
It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
string? appliedManifest = null;
|
||||
k8sFactory.Setup(f => f.ApplyManifestAsync(
|
||||
It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.Callback<string, string, CancellationToken>((manifest, _, _) => appliedManifest = manifest)
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
CnpgDatabase database = await sut.CreateDatabaseAsync(tenant.Id, cnpg.Id, "syncdb");
|
||||
|
||||
// Act — push the credentials to Kubernetes.
|
||||
|
||||
await sut.SyncDatabaseCredentialsToK8sAsync(tenant.Id, cnpg.Id, database.Id);
|
||||
|
||||
// Assert — a K8s Secret manifest with all credential fields should be applied.
|
||||
|
||||
appliedManifest.Should().NotBeNull();
|
||||
appliedManifest.Should().Contain("kind: Secret");
|
||||
appliedManifest.Should().Contain("name: sync-cluster-syncdb-credentials");
|
||||
appliedManifest.Should().Contain("namespace: databases");
|
||||
appliedManifest.Should().Contain("HOST:");
|
||||
appliedManifest.Should().Contain("PORT:");
|
||||
appliedManifest.Should().Contain("DATABASE:");
|
||||
appliedManifest.Should().Contain("USERNAME:");
|
||||
appliedManifest.Should().Contain("PASSWORD:");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user