use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class BlocklistValidatorTest method givenUpdateWithBlocklistedProperties_shouldFail.
@Test
void givenUpdateWithBlocklistedProperties_shouldFail() {
PgConfigReview review = JsonUtil.readFromJson("pgconfig_allow_request/valid_pgconfig_update.json", PgConfigReview.class);
StackGresPostgresConfig pgConfig = review.getRequest().getObject();
String[] blocklistedProperties = addBlocklistProperties(pgConfig);
assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String errorMessage = ex.getResult().getMessage();
assertEquals("Invalid postgres configuration, properties: " + String.join(", ", blocklistedProperties) + " cannot be settled", errorMessage);
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class PgConfigUpdateValidatorTest method updatesOfPgVersion_shouldFail.
@Test
void updatesOfPgVersion_shouldFail() {
final AdmissionRequest<StackGresPostgresConfig> request = review.getRequest();
request.getObject().getSpec().setPostgresVersion("12");
request.getOldObject().getSpec().setPostgresVersion("11");
ValidationFailed vf = ValidationUtils.assertErrorType(ErrorType.FORBIDDEN_CR_UPDATE, () -> validator.validate(review));
ValidationUtils.checkErrorCause(vf.getResult(), "spec.postgresVersion", "postgresVersion is not updatable", "FieldNotUpdatable");
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class StorageClassValidatorTest method giveInvalidStorageClassOnCreation_shouldFail.
@Test
void giveInvalidStorageClassOnCreation_shouldFail() {
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.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Storage class " + storageClass + " not found", resultMessage);
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class DbOpsConstraintValidatorTest method invalidDuration_shouldFailWithMessage.
@Test
void invalidDuration_shouldFailWithMessage() {
StackGresDbOpsReview review = getValidReview();
review.getRequest().getObject().getSpec().getBenchmark().getPgbench().setDuration("P5M");
ValidationFailed assertThrows = assertThrows(ValidationFailed.class, () -> validator.validate(review));
assertEquals("SGDbOps has invalid properties. " + "duration must be positive and in ISO 8601 duration format: `PnDTnHnMn.nS`.", assertThrows.getMessage());
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class PoolingBlocklistValidatorTest method givenConfigurationWithDatabasesBlockedParameters_shouldFail.
@Test
void givenConfigurationWithDatabasesBlockedParameters_shouldFail() {
PoolingReview review = getCreatePoolingReview();
var pgBouncer = review.getRequest().getObject().getSpec().getPgBouncer();
pgBouncer.getPgbouncerIni().setDatabases(new HashMap<>());
pgBouncer.getPgbouncerIni().getDatabases().put("foodb", Map.of("user", "user1", "host", "example.com"));
ValidationFailed assertThrows = assertThrows(ValidationFailed.class, () -> validator.validate(review));
assertEquals("Invalid PgBouncer configuration, properties: [host, user] cannot be set", assertThrows.getMessage());
}
Aggregations