use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class BackupConfigSourceValidatorTest method givenNonExistentAccountKeyForAzureBlobStorageCredentialsOnCreation_shouldFail.
@Test
void givenNonExistentAccountKeyForAzureBlobStorageCredentialsOnCreation_shouldFail() throws ValidationFailed {
final BackupConfigReview review = getEmptyReview();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
String accountName = "secret1";
String accountKey = "key1";
String accessKeyName = "secret2";
String accessKeyKey = "key2";
setAzureBlobCredentials(review, accountName, accountKey, accessKeyName, accessKeyKey);
when(secretFinder.findByNameAndNamespace(accountName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(accountKey + "-wrong", ResourceUtil.encodeSecret("account"))).build()));
ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
assertEquals("Invalid backup configuration, key " + accountKey + " of secret " + accountName + " for account of azureblob credentials not found", ex.getResult().getMessage());
verify(secretFinder).findByNameAndNamespace(eq(accountName), eq(namespace));
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class StorageClassValidatorTest method giveAnAttemptToUpdateToAUnknownStorageClass_shouldFail.
@Test
void giveAnAttemptToUpdateToAUnknownStorageClass_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/storage_class_config_update.json", StackGresClusterReview.class);
String storageClass = review.getRequest().getObject().getSpec().getPod().getPersistentVolume().getStorageClass();
when(storageClassFinder.findByName(storageClass)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Cannot update to storage class " + storageClass + " because it doesn't exists", resultMessage);
verify(storageClassFinder).findByName(eq(storageClass));
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class DistributedLogsReferenceValidatorTest method giveInvalidStackGresReferenceOnCreation_shouldFail.
@Test
void giveInvalidStackGresReferenceOnCreation_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
String distributedLogsName = review.getRequest().getObject().getSpec().getDistributedLogs().getDistributedLogs();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(distributedLogsFinder.findByNameAndNamespace(distributedLogsName, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Distributed logs " + distributedLogsName + " not found", resultMessage);
verify(distributedLogsFinder).findByNameAndNamespace(anyString(), anyString());
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class DistributedLogsReferenceValidatorTest method giveAnAttemptToUpdateToAnUnknownProfile_shouldFail.
@Test
void giveAnAttemptToUpdateToAnUnknownProfile_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/distributed_logs_update.json", StackGresClusterReview.class);
String distributedLogsName = review.getRequest().getObject().getSpec().getDistributedLogs().getDistributedLogs();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(distributedLogsFinder.findByNameAndNamespace(distributedLogsName, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Distributed logs " + distributedLogsName + " not found", resultMessage);
verify(distributedLogsFinder).findByNameAndNamespace(anyString(), anyString());
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenInvalidPostgresVersion_shouldFail.
@Test
void givenInvalidPostgresVersion_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/invalid_creation_no_pg_version.json", StackGresClusterReview.class);
String postgresVersion = getRandomInvalidPostgresVersion();
review.getRequest().getObject().getSpec().getPostgres().setVersion(postgresVersion);
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertTrue(resultMessage.contains("Unsupported postgres version " + postgresVersion));
verify(configFinder, never()).findByNameAndNamespace(anyString(), anyString());
}
Aggregations