use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenEmptyPostgresConfigReference_shouldFail.
@Test
void givenEmptyPostgresConfigReference_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
spec.getConfiguration().setPostgresConfig("");
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("sgPostgresConfig 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 givenNoPostgresConfigReference_shouldFail.
@Test
void givenNoPostgresConfigReference_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
spec.getConfiguration().setPostgresConfig(null);
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("sgPostgresConfig 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 givenPostgresConfigUpdate_shouldFail.
@Test
void givenPostgresConfigUpdate_shouldFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/postgres_config_update.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
String postgresProfile = spec.getConfiguration().getPostgresConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
review.getRequest().getObject().getSpec().getPostgres().setVersion(getRandomPostgresVersion());
when(configFinder.findByNameAndNamespace(eq(postgresProfile), eq(namespace))).thenReturn(Optional.empty());
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("Invalid sgPostgresConfig value " + postgresProfile, resultMessage);
verify(configFinder).findByNameAndNamespace(eq(postgresProfile), eq(namespace));
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class ClusterConstraintValidatorTest method invalidLongNames_shouldFail.
@ParameterizedTest
@ValueSource(strings = { "hardcover-lady-somebody-arrives-specialty-risk-stocking-nodes-" + "fisheries-introduces-5", "suzuki-stroke-rail-remix-suite-flux-diploma-slip-airfare-extremely-1", "mozilla-rose-types-border-biome-upright-weak-promote-monday-1234" })
void invalidLongNames_shouldFail(String name) {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getMetadata().setName(name);
ValidationFailed message = assertThrows(ValidationFailed.class, () -> validator.validate(review));
assertEquals("Valid name must be 53 characters or less", message.getMessage());
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class StorageValidatorTest method givenCreationWithGcsAndS3Properties_shouldFail.
@Test
void givenCreationWithGcsAndS3Properties_shouldFail() {
BackupConfigReview review = JsonUtil.readFromJson("backupconfig_allow_request/invalid_creation_gcs_and_s3.json", BackupConfigReview.class);
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String errorMessage = ex.getResult().getMessage();
assertEquals("Invalid backup configuration," + " source gcs must not be set when source type is s3", errorMessage);
}
Aggregations