use of io.stackgres.operator.resource.PrometheusScanner in project stackgres by ongres.
the class ClusterRequiredResourcesGeneratorTest method givenADefaultPrometheusInstallation_shouldGenerateServiceMonitors.
@Test
void givenADefaultPrometheusInstallation_shouldGenerateServiceMonitors() {
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);
when(prometheusScanner.findResources()).thenReturn(Optional.of(JsonUtil.readFromJson("prometheus/prometheus_list.json", PrometheusConfigList.class).getItems()));
List<HasMetadata> generatedResources = generator.getRequiredResources(cluster);
var serviceMonitors = generatedResources.stream().filter(r -> r.getKind().equals(ServiceMonitor.KIND)).collect(Collectors.toUnmodifiableList());
assertEquals(2, serviceMonitors.size());
verify(prometheusScanner).findResources();
}
Aggregations