use of io.stackgres.common.resource.ClusterFinder 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));
}
Aggregations