Search in sources :

Example 16 with StackGresClusterReview

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);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) Test(org.junit.jupiter.api.Test)

Example 17 with StackGresClusterReview

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);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 18 with StackGresClusterReview

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);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 19 with StackGresClusterReview

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));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 20 with StackGresClusterReview

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.");
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)109 Test (org.junit.jupiter.api.Test)103 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)31 ConstraintValidationTest (io.stackgres.operator.validation.ConstraintValidationTest)29 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)26 ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)24 StackGresClusterScriptEntry (io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry)15 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)13 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)12 StackGresClusterPodScheduling (io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling)9 StackGresClusterScriptFrom (io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom)9 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)9 SecretKeySelector (io.stackgres.common.crd.SecretKeySelector)8 Toleration (io.stackgres.common.crd.Toleration)7 QuarkusTest (io.quarkus.test.junit.QuarkusTest)5 ConfigMapKeySelector (io.stackgres.common.crd.ConfigMapKeySelector)5 StackGresClusterSsl (io.stackgres.common.crd.sgcluster.StackGresClusterSsl)4 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)3 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 List (java.util.List)2