Search in sources :

Example 1 with StackGresClusterReview

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

Example 2 with StackGresClusterReview

use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.

the class PostgresVersionValidatorTest method givenMajorPostgresVersionUpdate_shouldPass.

@Test
void givenMajorPostgresVersionUpdate_shouldPass() throws ValidationFailed {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/major_postgres_version_update.json", StackGresClusterReview.class);
    review.getRequest().getObject().getSpec().getPostgres().setVersion(firstPgMajorVersion);
    review.getRequest().getOldObject().getSpec().getPostgres().setVersion(secondPgMajorVersion);
    validator.validate(review);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) Test(org.junit.jupiter.api.Test)

Example 3 with StackGresClusterReview

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

Example 4 with StackGresClusterReview

use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.

the class PostgresVersionValidatorTest method givenMinorPostgresVersionUpdate_shouldPass.

@Test
void givenMinorPostgresVersionUpdate_shouldPass() throws ValidationFailed {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/minor_postgres_version_update.json", StackGresClusterReview.class);
    review.getRequest().getObject().getSpec().getPostgres().setVersion(firstPgMinorVersion);
    review.getRequest().getOldObject().getSpec().getPostgres().setVersion(secondPgMinorVersion);
    validator.validate(review);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) Test(org.junit.jupiter.api.Test)

Example 5 with StackGresClusterReview

use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.

the class PostgresVersionValidatorTest method givenValidPostgresVersion_shouldNotFail.

@Test
void givenValidPostgresVersion_shouldNotFail() throws ValidationFailed {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
    StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
    String postgresProfile = spec.getConfiguration().getPostgresConfig();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    when(configFinder.findByNameAndNamespace(eq(postgresProfile), eq(namespace))).thenReturn(Optional.of(postgresConfig));
    final String randomVersion = getRandomPostgresVersion();
    spec.getPostgres().setVersion(randomVersion);
    postgresConfig.getSpec().setPostgresVersion(getMajorPostgresVersion(randomVersion));
    validator.validate(review);
    verify(configFinder).findByNameAndNamespace(eq(postgresProfile), eq(namespace));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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