use of io.stackgres.common.resource.BackupConfigFinder in project stackgres by ongres.
the class BackupRequiredResourcesGeneratorTest method givenValidCluster_getRequiredResourcesAllReturnedResourcesShouldHaveTheOwnerReference.
@Test
void givenValidCluster_getRequiredResourcesAllReturnedResourcesShouldHaveTheOwnerReference() {
final String backupNamespace = backup.getMetadata().getNamespace();
final String clusterName = backup.getSpec().getSgCluster();
final StackGresClusterSpec clusterSpec = cluster.getSpec();
final StackGresClusterConfiguration clusterConfiguration = clusterSpec.getConfiguration();
final String backupConfigName = clusterConfiguration.getBackupConfig();
when(clusterFinder.findByNameAndNamespace(any(), any())).thenReturn(Optional.of(cluster));
when(backupConfigFinder.findByNameAndNamespace(backupConfigName, backupNamespace)).thenReturn(Optional.of(this.backupConfig));
List<HasMetadata> resources = generator.getRequiredResources(backup);
resources.forEach(resource -> {
assertNotNull(resource.getMetadata().getOwnerReferences(), "Resource " + resource.getMetadata().getName() + " doesn't owner references");
if (resource.getMetadata().getOwnerReferences().size() == 0) {
fail("Resource " + resource.getMetadata().getName() + " doesn't have any owner");
}
assertTrue(resource.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getApiVersion().equals(HasMetadata.getApiVersion(StackGresBackup.class)) && ownerReference.getKind().equals(HasMetadata.getKind(StackGresBackup.class)) && ownerReference.getName().equals(backup.getMetadata().getName()) && ownerReference.getUid().equals(backup.getMetadata().getUid()) && Optional.ofNullable(ownerReference.getBlockOwnerDeletion()).orElse(Boolean.FALSE).equals(Boolean.FALSE)));
});
verify(clusterFinder, times(1)).findByNameAndNamespace(any(), any());
verify(clusterFinder).findByNameAndNamespace(eq(clusterName), eq(backupNamespace));
verify(backupConfigFinder, times(1)).findByNameAndNamespace(any(), any());
verify(backupConfigFinder).findByNameAndNamespace(eq(backupConfigName), eq(backupNamespace));
}
use of io.stackgres.common.resource.BackupConfigFinder in project stackgres by ongres.
the class ClusterRequiredResourcesGeneratorTest method givenValidCluster_getRequiredResourcesAllReturnedResourcesShouldHaveTheOwnerReference.
@Test
void givenValidCluster_getRequiredResourcesAllReturnedResourcesShouldHaveTheOwnerReference() {
final ObjectMeta metadata = cluster.getMetadata();
final String clusterNamespace = metadata.getNamespace();
final StackGresClusterSpec clusterSpec = cluster.getSpec();
final StackGresClusterConfiguration clusterConfiguration = clusterSpec.getConfiguration();
final String backupConfigName = clusterConfiguration.getBackupConfig();
mockBackupConfig(clusterNamespace, backupConfigName);
final String postgresConfigName = clusterConfiguration.getPostgresConfig();
mockPgConfig(clusterNamespace, postgresConfigName);
final String connectionPoolingConfig = clusterConfiguration.getConnectionPoolingConfig();
mockPoolingConfig(clusterNamespace, connectionPoolingConfig);
final String resourceProfile = clusterSpec.getResourceProfile();
when(profileConfigFinder.findByNameAndNamespace(resourceProfile, clusterNamespace)).thenReturn(Optional.of(instanceProfile));
when(backupScanner.getResources()).thenReturn(backups);
mockSecrets(clusterNamespace);
List<HasMetadata> resources = generator.getRequiredResources(cluster);
resources.forEach(resource -> {
assertNotNull(resource.getMetadata().getOwnerReferences(), "Resource " + resource.getMetadata().getName() + " doesn't owner references");
if (resource.getMetadata().getOwnerReferences().size() == 0) {
fail("Resource " + resource.getMetadata().getName() + " doesn't have any owner");
}
assertTrue(resource.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getApiVersion().equals(HasMetadata.getApiVersion(StackGresCluster.class)) && ownerReference.getKind().equals(HasMetadata.getKind(StackGresCluster.class)) && ownerReference.getName().equals(cluster.getMetadata().getName()) && ownerReference.getUid().equals(cluster.getMetadata().getUid()) && Optional.ofNullable(ownerReference.getBlockOwnerDeletion()).orElse(Boolean.FALSE).equals(Boolean.FALSE)));
});
verify(backupConfigFinder).findByNameAndNamespace(backupConfigName, clusterNamespace);
verify(postgresConfigFinder).findByNameAndNamespace(postgresConfigName, clusterNamespace);
verify(poolingConfigFinder).findByNameAndNamespace(connectionPoolingConfig, clusterNamespace);
verify(profileConfigFinder).findByNameAndNamespace(resourceProfile, clusterNamespace);
verify(backupScanner, atLeastOnce()).getResources();
}
Aggregations