use of io.stackgres.operator.common.StackGresClusterReview 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.operator.common.StackGresClusterReview in project stackgres by ongres.
the class StorageClassValidatorTest method giveAnAttemptToDelete_shouldNotFail.
@Test
void giveAnAttemptToDelete_shouldNotFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/storage_class_config_update.json", StackGresClusterReview.class);
review.getRequest().setOperation(Operation.DELETE);
validator.validate(review);
verify(storageClassFinder, never()).findByName(anyString());
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class StorageClassValidatorTest method givenValidStorageClassOnCreation_shouldNotFail.
@Test
void givenValidStorageClassOnCreation_shouldNotFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
String storageClass = review.getRequest().getObject().getSpec().getPod().getPersistentVolume().getStorageClass();
when(storageClassFinder.findByName(storageClass)).thenReturn(Optional.of(DEFAULT_STORAGE_CLASS));
validator.validate(review);
verify(storageClassFinder).findByName(eq(storageClass));
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterValidationQuarkusTest method given_invalidStackGresClusterName_shouldFail.
@Test
void given_invalidStackGresClusterName_shouldFail() {
StackGresClusterReview clusterReview = getConstraintClusterReview();
StackGresCluster cluster = clusterReview.getRequest().getObject();
cluster.getMetadata().setName("postgres-13.0-to-13.1");
RestAssured.given().body(clusterReview).contentType(ContentType.JSON).accept(ContentType.JSON).post(ValidationUtil.CLUSTER_VALIDATION_PATH).then().body("response.allowed", is(false), "kind", is("AdmissionReview"), "response.status.code", is(422), "response.status.message", is("Name must consist of lower case alphanumeric " + "characters or '-', start with an alphabetic character, " + "and end with an alphanumeric character")).statusCode(200);
}
use of io.stackgres.operator.common.StackGresClusterReview 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());
}
Aggregations