Search in sources :

Example 96 with StackGresClusterReview

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

the class PostgresVersionValidatorTest method givenInvalidPostgresVersion_shouldFail.

@Test
void givenInvalidPostgresVersion_shouldFail() {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/invalid_creation_no_pg_version.json", StackGresClusterReview.class);
    String postgresVersion = getRandomInvalidPostgresVersion();
    review.getRequest().getObject().getSpec().getPostgres().setVersion(postgresVersion);
    ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
        validator.validate(review);
    });
    String resultMessage = exception.getResult().getMessage();
    assertTrue(resultMessage.contains("Unsupported postgres version " + postgresVersion));
    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 97 with StackGresClusterReview

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

the class PostgresVersionValidatorTest method givenInconsistentPostgresVersion_shouldFail.

@Test
void givenInconsistentPostgresVersion_shouldFail() {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/invalid_creation_pg_version.json", StackGresClusterReview.class);
    review.getRequest().getObject().getSpec().getPostgres().setVersion(secondPgMajorVersion);
    postgresConfig.getSpec().setPostgresVersion(firstPgMajorVersion);
    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));
    ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
        validator.validate(review);
    });
    String resultMessage = exception.getResult().getMessage();
    assertEquals("Invalid postgres version, must be " + firstPgMajorVersion + " to use sgPostgresConfig postgresconf", resultMessage);
    verify(configFinder).findByNameAndNamespace(eq(postgresProfile), eq(namespace));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 98 with StackGresClusterReview

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

the class PostgresVersionValidatorTest method givenNoPostgresVersion_shouldFail.

@Test
void givenNoPostgresVersion_shouldFail() throws ValidationFailed {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/invalid_creation_no_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 99 with StackGresClusterReview

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

the class PostgresVersionValidatorTest method givenInvalidPostgresConfigReference_shouldFail.

@Test
void givenInvalidPostgresConfigReference_shouldFail() {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
    review.getRequest().getObject().getSpec().getPostgres().setVersion(firstPgMajorVersion);
    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.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));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 100 with StackGresClusterReview

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

the class ProfileReferenceValidatorTest method giveAnAttemptToUpdateToAnKnownProfile_shouldNotFail.

@Test
void giveAnAttemptToUpdateToAnKnownProfile_shouldNotFail() throws ValidationFailed {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/profile_config_update.json", StackGresClusterReview.class);
    String resourceProfile = review.getRequest().getObject().getSpec().getResourceProfile();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    StackGresProfile profileSizeS = JsonUtil.readFromJson("stackgres_profiles/size-s.json", StackGresProfile.class);
    when(profileFinder.findByNameAndNamespace(resourceProfile, namespace)).thenReturn(Optional.of(profileSizeS));
    validator.validate(review);
    verify(profileFinder).findByNameAndNamespace(anyString(), anyString());
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresProfile(io.stackgres.common.crd.sgprofile.StackGresProfile) 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