use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ScriptsConfigValidatorTest method givenACreationUsingScriptsFromPlainConfigMap_shouldValidateConfigMapReference.
@Test
void givenACreationUsingScriptsFromPlainConfigMap_shouldValidateConfigMapReference() throws ValidationFailed {
final StackGresClusterReview review = getCreationReview();
String randomConfigMapName = StringUtil.generateRandom();
String randomConfigMapKey = StringUtil.generateRandom();
prepareForConfigMap(review, randomConfigMapName, randomConfigMapKey);
final StackGresCluster cluster = review.getRequest().getObject();
final String namespace = cluster.getMetadata().getNamespace();
when(configMapFinder.findByNameAndNamespace(randomConfigMapName, namespace)).thenReturn(Optional.of(new ConfigMapBuilder().withNewMetadata().withName(randomConfigMapName).withNamespace(namespace).endMetadata().withData(ImmutableMap.of(randomConfigMapKey, "CREATE DATABASE test;")).build()));
validator.validate(review);
final List<StackGresClusterScriptEntry> scripts = cluster.getSpec().getInitData().getScripts();
verify(configMapFinder, times(scripts.size())).findByNameAndNamespace(randomConfigMapName, namespace);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterValidationQuarkusTest method given_withoutInstalledExtensions_shouldFail.
@Test
void given_withoutInstalledExtensions_shouldFail() {
StackGresClusterReview clusterReview = getConstraintClusterReview();
clusterReview.getRequest().getObject().getSpec().setToInstallPostgresExtensions(null);
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(400), "response.status.message", is("Extensions dblink, pg_stat_statements, plpgsql, plpython3u are missing.")).statusCode(200);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterValidationQuarkusTest method given_invalidStackGresClusterLongName_shouldFail.
@Test
void given_invalidStackGresClusterLongName_shouldFail() {
StackGresClusterReview clusterReview = getConstraintClusterReview();
StackGresCluster cluster = clusterReview.getRequest().getObject();
cluster.getMetadata().setName("husked-condition-calculus-ridden-pancreas-heave-extented");
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("Valid name must be 53 characters or less")).statusCode(200);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class DistributedLogsReferenceValidatorTest method givenValidStackGresReferenceOnCreation_shouldNotFail.
@Test
void givenValidStackGresReferenceOnCreation_shouldNotFail() throws ValidationFailed {
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.of(distributedLogs));
validator.validate(review);
verify(distributedLogsFinder).findByNameAndNamespace(eq(distributedLogsName), eq(namespace));
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ExtensionsValidatorTest method givenACreationWithMissingExtensions_shouldFail.
@Test
void givenACreationWithMissingExtensions_shouldFail() {
final StackGresClusterReview review = getCreationReview();
review.getRequest().getObject().getSpec().getPostgres().setExtensions(null);
ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.MISSING_EXTENSION, "Extensions dblink, pg_stat_statements, plpgsql, plpython3u are missing.");
}
Aggregations