Search in sources :

Example 21 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class BlocklistValidatorTest method givenUpdateWithBlocklistedProperties_shouldFail.

@Test
void givenUpdateWithBlocklistedProperties_shouldFail() {
    PgConfigReview review = JsonUtil.readFromJson("pgconfig_allow_request/valid_pgconfig_update.json", PgConfigReview.class);
    StackGresPostgresConfig pgConfig = review.getRequest().getObject();
    String[] blocklistedProperties = addBlocklistProperties(pgConfig);
    assertThrows(ValidationFailed.class, () -> {
        validator.validate(review);
    });
    ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
        validator.validate(review);
    });
    String errorMessage = ex.getResult().getMessage();
    assertEquals("Invalid postgres configuration, properties: " + String.join(", ", blocklistedProperties) + " cannot be settled", errorMessage);
}
Also used : PgConfigReview(io.stackgres.operator.common.PgConfigReview) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig) Test(org.junit.jupiter.api.Test)

Example 22 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class PgConfigUpdateValidatorTest method updatesOfPgVersion_shouldFail.

@Test
void updatesOfPgVersion_shouldFail() {
    final AdmissionRequest<StackGresPostgresConfig> request = review.getRequest();
    request.getObject().getSpec().setPostgresVersion("12");
    request.getOldObject().getSpec().setPostgresVersion("11");
    ValidationFailed vf = ValidationUtils.assertErrorType(ErrorType.FORBIDDEN_CR_UPDATE, () -> validator.validate(review));
    ValidationUtils.checkErrorCause(vf.getResult(), "spec.postgresVersion", "postgresVersion is not updatable", "FieldNotUpdatable");
}
Also used : ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) StackGresPostgresConfig(io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig) Test(org.junit.jupiter.api.Test)

Example 23 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class StorageClassValidatorTest method giveInvalidStorageClassOnCreation_shouldFail.

@Test
void giveInvalidStorageClassOnCreation_shouldFail() {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
    String storageClass = review.getRequest().getObject().getSpec().getPod().getPersistentVolume().getStorageClass();
    when(storageClassFinder.findByName(storageClass)).thenReturn(Optional.empty());
    ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
        validator.validate(review);
    });
    String resultMessage = ex.getMessage();
    assertEquals("Storage class " + storageClass + " not found", 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 24 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class DbOpsConstraintValidatorTest method invalidDuration_shouldFailWithMessage.

@Test
void invalidDuration_shouldFailWithMessage() {
    StackGresDbOpsReview review = getValidReview();
    review.getRequest().getObject().getSpec().getBenchmark().getPgbench().setDuration("P5M");
    ValidationFailed assertThrows = assertThrows(ValidationFailed.class, () -> validator.validate(review));
    assertEquals("SGDbOps has invalid properties. " + "duration must be positive and in ISO 8601 duration format: `PnDTnHnMn.nS`.", assertThrows.getMessage());
}
Also used : StackGresDbOpsReview(io.stackgres.operator.common.StackGresDbOpsReview) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) Test(org.junit.jupiter.api.Test) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest)

Example 25 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class PoolingBlocklistValidatorTest method givenConfigurationWithDatabasesBlockedParameters_shouldFail.

@Test
void givenConfigurationWithDatabasesBlockedParameters_shouldFail() {
    PoolingReview review = getCreatePoolingReview();
    var pgBouncer = review.getRequest().getObject().getSpec().getPgBouncer();
    pgBouncer.getPgbouncerIni().setDatabases(new HashMap<>());
    pgBouncer.getPgbouncerIni().getDatabases().put("foodb", Map.of("user", "user1", "host", "example.com"));
    ValidationFailed assertThrows = assertThrows(ValidationFailed.class, () -> validator.validate(review));
    assertEquals("Invalid PgBouncer configuration, properties: [host, user] cannot be set", assertThrows.getMessage());
}
Also used : ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) PoolingReview(io.stackgres.operator.common.PoolingReview) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)61 Test (org.junit.jupiter.api.Test)46 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)24 BackupConfigReview (io.stackgres.operator.common.BackupConfigReview)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)10 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)5 Status (io.fabric8.kubernetes.api.model.Status)4 StackGresPostgresConfig (io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig)4 StatusBuilder (io.fabric8.kubernetes.api.model.StatusBuilder)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 StatusDetailsBuilder (io.fabric8.kubernetes.api.model.StatusDetailsBuilder)2 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)2 PgConfigReview (io.stackgres.operator.common.PgConfigReview)2 StackGresDbOpsReview (io.stackgres.operator.common.StackGresDbOpsReview)2 Operation (io.stackgres.operatorframework.admissionwebhook.Operation)2 List (java.util.List)2 ImmutableList (com.google.common.collect.ImmutableList)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1