use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class RestoreConfigValidatorTest method givenAnUpdate_shouldFail.
@Test
void givenAnUpdate_shouldFail() {
final StackGresClusterReview review = getUpdateReview();
ValidationUtils.assertValidationFailed(() -> validator.validate(review), "Cannot update cluster's restore configuration");
verify(scanner, never()).findResources();
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class RestoreConfigValidatorTest method givenAInvalidCreation_shouldFail.
@Test
void givenAInvalidCreation_shouldFail() {
final StackGresClusterReview review = getCreationReview();
StackGresCluster cluster = review.getRequest().getObject();
StackGresClusterRestore restoreConfig = cluster.getSpec().getInitData().getRestore();
String stackgresBackup = restoreConfig.getFromBackup().getUid();
when(scanner.findResources()).thenReturn(Optional.empty());
ValidationUtils.assertValidationFailed(() -> validator.validate(review), "Backup uid " + stackgresBackup + " not found");
verify(scanner).findResources();
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class RestoreConfigValidatorTest method givenACreationWithBackupFromDifferentPgVersion_shouldFail.
@Test
void givenACreationWithBackupFromDifferentPgVersion_shouldFail() {
final StackGresClusterReview review = getCreationReview();
review.getRequest().getObject().getSpec().getPostgres().setVersion(secondPgMajorVersion);
String stackgresBackup = review.getRequest().getObject().getSpec().getInitData().getRestore().getFromBackup().getUid();
StackGresBackup backup = backupList.getItems().stream().filter(b -> b.getMetadata().getUid().equals(stackgresBackup)).findFirst().orElseThrow(AssertionError::new);
backup.getStatus().getBackupInformation().setPostgresVersion(firstPgMajorVersionNumber);
when(scanner.findResources()).thenReturn(Optional.of(backupList.getItems()));
ValidationUtils.assertValidationFailed(() -> validator.validate(review), "Cannot restore from backup " + stackgresBackup + " because it comes from an incompatible postgres version");
verify(scanner).findResources();
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ScriptsConfigValidatorTest method givenACreationUsingScriptFromNonexistentSecretKey_shouldFail.
@Test
void givenACreationUsingScriptFromNonexistentSecretKey_shouldFail() {
final StackGresClusterReview review = getCreationReview();
String randomSecretKey = StringUtil.generateRandom();
String randomSecretName = StringUtil.generateRandom();
final StackGresCluster cluster = review.getRequest().getObject();
prepareForSecret(review, randomSecretName, randomSecretKey);
final String namespace = cluster.getMetadata().getNamespace();
when(secretFinder.findByNameAndNamespace(randomSecretName, namespace)).thenReturn(Optional.of(new SecretBuilder().withNewMetadata().withName(randomSecretName).withNamespace(namespace).endMetadata().withData(ImmutableMap.of()).build()));
ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Key " + randomSecretKey + " does not exists in Secret " + randomSecretName);
verify(secretFinder).findByNameAndNamespace(randomSecretName, namespace);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ScriptsConfigValidatorTest method givenACreationUsingScriptFromNonexistentSecret_shouldFail.
@Test
void givenACreationUsingScriptFromNonexistentSecret_shouldFail() {
final StackGresClusterReview review = getCreationReview();
String randomSecretKey = StringUtil.generateRandom();
String randomSecretName = StringUtil.generateRandom();
final StackGresCluster cluster = review.getRequest().getObject();
prepareForSecret(review, randomSecretName, randomSecretKey);
final String namespace = cluster.getMetadata().getNamespace();
when(secretFinder.findByNameAndNamespace(randomSecretName, namespace)).thenReturn(Optional.empty());
ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Referenced Secret " + randomSecretName + " does not exists in namespace " + namespace);
verify(secretFinder).findByNameAndNamespace(randomSecretName, namespace);
}
Aggregations