use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class BackupSourceValidatorTest method giveAnAttemptToUpdateToAnKnownBackup_shouldNotFail.
@Test
void giveAnAttemptToUpdateToAnKnownBackup_shouldNotFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/backup_config_update.json", StackGresClusterReview.class);
String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(backupConfig, namespace)).thenReturn(Optional.of(this.backupConfig));
validator.validate(review);
verify(configFinder).findByNameAndNamespace(eq(backupConfig), eq(namespace));
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class BackupSourceValidatorTest method giveInvalidStackGresBackupOnCreation_shouldFail.
@Test
void giveInvalidStackGresBackupOnCreation_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(backupConfig, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Backup config " + backupConfig + " not found", resultMessage);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class BackupSourceValidatorTest method giveAnAttemptToUpdateToAnUnknownBackupConfig_shouldFail.
@Test
void giveAnAttemptToUpdateToAnUnknownBackupConfig_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/backup_config_update.json", StackGresClusterReview.class);
String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(backupConfig, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Cannot update to backup config " + backupConfig + " because it doesn't exists", resultMessage);
verify(configFinder).findByNameAndNamespace(eq(backupConfig), eq(namespace));
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class BackupSourceValidatorTest method giveAnAttemptToDelete_shouldNotFail.
@Test
void giveAnAttemptToDelete_shouldNotFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/backup_config_update.json", StackGresClusterReview.class);
review.getRequest().setOperation(Operation.DELETE);
String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
validator.validate(review);
verify(configFinder, never()).findByNameAndNamespace(eq(backupConfig), eq(namespace));
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method scriptFromConfigMapWithEmptyKey_shouldFail.
@Test
void scriptFromConfigMapWithEmptyKey_shouldFail() {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().setInitData(new StackGresClusterInitData());
review.getRequest().getObject().getSpec().getInitData().setScripts(new ArrayList<>());
review.getRequest().getObject().getSpec().getInitData().getScripts().add(new StackGresClusterScriptEntry());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScriptFrom(new StackGresClusterScriptFrom());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().setConfigMapKeyRef(new ConfigMapKeySelector());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setName("test");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setKey("");
checkErrorCause(SecretKeySelector.class, "spec.initData.scripts[0].scriptFrom.configMapKeyRef.key", "isKeyNotEmpty", review, AssertTrue.class);
}
Aggregations