Search in sources :

Example 1 with BackupConfigReview

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

the class StorageValidatorTest method givenCreationWithGcsAndS3Properties_shouldFail.

@Test
void givenCreationWithGcsAndS3Properties_shouldFail() {
    BackupConfigReview review = JsonUtil.readFromJson("backupconfig_allow_request/invalid_creation_gcs_and_s3.json", BackupConfigReview.class);
    ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
        validator.validate(review);
    });
    String errorMessage = ex.getResult().getMessage();
    assertEquals("Invalid backup configuration," + " source gcs must not be set when source type is s3", errorMessage);
}
Also used : ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test)

Example 2 with BackupConfigReview

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

the class BackupConfigConstraintValidationTest method nullStorage_shouldFail.

@Test
void nullStorage_shouldFail() {
    BackupConfigReview review = getValidReview();
    review.getRequest().getObject().getSpec().setStorage(null);
    checkNotNullErrorCause(StackGresBackupConfigSpec.class, "spec.storage", review);
}
Also used : BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest)

Example 3 with BackupConfigReview

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

the class BackupConfigConstraintValidationTest method zeroOrNegativeRetention_shouldFail.

@Test
void zeroOrNegativeRetention_shouldFail() {
    int negativeRetention = new Random().nextInt(10) * -1;
    BackupConfigReview review = getValidReview();
    review.getRequest().getObject().getSpec().getBaseBackups().setRetention(negativeRetention);
    checkErrorCause(StackGresBaseBackupConfig.class, "spec.baseBackups.retention", review, Positive.class);
}
Also used : Random(java.util.Random) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest)

Example 4 with BackupConfigReview

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

the class BackupConfigConstraintValidationTest method givenStorageClass_shouldPass.

@ParameterizedTest
@EnumSource(value = StorageClassS3.class)
void givenStorageClass_shouldPass(StorageClassS3 storageClass) {
    BackupConfigReview review = JsonUtil.readFromJson("backupconfig_allow_request/update.json", BackupConfigReview.class);
    review.getRequest().getObject().getSpec().getStorage().getS3Compatible().setStorageClass(storageClass.toString());
    assertDoesNotThrow(() -> validator.validate(review));
}
Also used : BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with BackupConfigReview

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

the class BackupConfigConstraintValidationTest method getInvalidReview.

@Override
protected BackupConfigReview getInvalidReview() {
    final BackupConfigReview backupConfigReview = JsonUtil.readFromJson("backupconfig_allow_request/create.json", BackupConfigReview.class);
    backupConfigReview.getRequest().getObject().setSpec(null);
    return backupConfigReview;
}
Also used : BackupConfigReview(io.stackgres.operator.common.BackupConfigReview)

Aggregations

BackupConfigReview (io.stackgres.operator.common.BackupConfigReview)31 Test (org.junit.jupiter.api.Test)25 ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)17 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ConstraintValidationTest (io.stackgres.operator.validation.ConstraintValidationTest)4 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)1 StackGresBackupConfigSpec (io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfigSpec)1 AwsS3Storage (io.stackgres.common.crd.storages.AwsS3Storage)1 BackupStorage (io.stackgres.common.crd.storages.BackupStorage)1 DefaultValuesMutatorTest (io.stackgres.operator.mutation.DefaultValuesMutatorTest)1 Random (java.util.Random)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1