use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenAnEmptyPostgresVersion_shouldFail.
@Test
void givenAnEmptyPostgresVersion_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/invalid_creation_empty_pg_version.json", StackGresClusterReview.class);
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("postgres version must be provided", resultMessage);
verify(configFinder, never()).findByNameAndNamespace(anyString(), anyString());
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenWrongMajorPostgresVersionUpdate_shouldFail.
@Test
void givenWrongMajorPostgresVersionUpdate_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/wrong_major_postgres_version_update.json", StackGresClusterReview.class);
review.getRequest().getObject().getSpec().getPostgres().setVersion(secondPgMajorVersion);
review.getRequest().getOldObject().getSpec().getPostgres().setVersion(firstPgMajorVersion);
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("postgres version can not be changed to a previous major version", resultMessage);
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class ProfileReferenceValidatorTest method giveAnAttemptToUpdateToAnUnknownProfile_shouldFail.
@Test
void giveAnAttemptToUpdateToAnUnknownProfile_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/profile_config_update.json", StackGresClusterReview.class);
String resourceProfile = review.getRequest().getObject().getSpec().getResourceProfile();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(profileFinder.findByNameAndNamespace(resourceProfile, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Cannot update to profile " + resourceProfile + " because it doesn't exists", resultMessage);
verify(profileFinder).findByNameAndNamespace(anyString(), anyString());
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class ValidationUtils method assertErrorType.
public static ValidationFailed assertErrorType(ErrorType errorType, Executable executable) {
ValidationFailed validation = assertThrows(ValidationFailed.class, executable);
assertErrorType(validation, errorType);
return validation;
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class ValidationUtils method assertValidationFailed.
public static void assertValidationFailed(Executable executable, String message, Integer code) {
ValidationFailed validation = assertThrows(ValidationFailed.class, executable);
assertEquals(message, validation.getResult().getMessage());
assertEquals(code, validation.getResult().getCode());
}
Aggregations